Skip to content

Commit

Permalink
mozzle: Use windows equivalent to linux's $HOME when on windows
Browse files Browse the repository at this point in the history
Otherwise the CF CLI config.json file will not be found:
  mozzle: error reading CF CLI config: error open ".cf\config.json": open .cf\config.json: The system cannot find the path specified.

Fixes #16.
  • Loading branch information
Bo0mer committed Jun 7, 2017
1 parent 9de8695 commit 764727c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
18 changes: 18 additions & 0 deletions cmd/mozzle/homedir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build !windows

package main

import (
"os"
)

func homeDir() string {
var homeDir string
switch {
case os.Getenv("CF_HOME") != "":
homeDir = os.Getenv("CF_HOME")
default:
homeDir = os.Getenv("HOME")
}
return homeDir
}
22 changes: 22 additions & 0 deletions cmd/mozzle/homedir_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build windows

package main

import (
"os"
)

func homeDir() string {
var homeDir string
switch {
case os.Getenv("CF_HOME") != "":
homeDir = os.Getenv("CF_HOME")
case os.Getenv("HOMEDRIVE")+os.Getenv("HOMEPATH") != "":
homeDir = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
default:
homeDir = os.Getenv("USERPROFILE")
}

return homeDir

}
6 changes: 1 addition & 5 deletions cmd/mozzle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ type cliConfig struct {
// The default location is CF_HOME/.cf/config.json.
// If the CF_HOME env variable is not set, it defaults to HOME env variable.
func cfcliConfig() (*cliConfig, error) {
var path string
if path = os.Getenv("CF_HOME"); path == "" {
path = os.Getenv("HOME")
}
path = filepath.Join(path, ".cf/config.json")
path := filepath.Join(homeDir(), ".cf", "config.json")
fd, err := os.Open(path)
if err != nil {
return nil, errors.Wrapf(err, "error open %q", path)
Expand Down

0 comments on commit 764727c

Please sign in to comment.