Skip to content

Commit

Permalink
refactor: cache cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Oct 12, 2020
1 parent 1086a48 commit 1ef2575
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions environment.go
Expand Up @@ -37,25 +37,31 @@ type environmentInfo interface {

type environment struct {
args *args
cwd string
}

func (env *environment) getenv(key string) string {
return os.Getenv(key)
}

func (env *environment) getcwd() string {
if env.cwd != "" {
return env.cwd
}
correctPath := func(pwd string) string {
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues
return strings.Replace(pwd, "c:", "C:", 1)
}
if env.args != nil && *env.args.PWD != "" {
return correctPath(*env.args.PWD)
env.cwd = correctPath(*env.args.PWD)
return env.cwd
}
dir, err := os.Getwd()
if err != nil {
return ""
}
return correctPath(dir)
env.cwd = correctPath(dir)
return env.cwd
}

func (env *environment) homeDir() string {
Expand Down

0 comments on commit 1ef2575

Please sign in to comment.