Skip to content

Commit 1ef2575

Browse files
refactor: cache cwd
1 parent 1086a48 commit 1ef2575

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

environment.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,31 @@ type environmentInfo interface {
3737

3838
type environment struct {
3939
args *args
40+
cwd string
4041
}
4142

4243
func (env *environment) getenv(key string) string {
4344
return os.Getenv(key)
4445
}
4546

4647
func (env *environment) getcwd() string {
48+
if env.cwd != "" {
49+
return env.cwd
50+
}
4751
correctPath := func(pwd string) string {
4852
// on Windows, and being case sentisitive and not consistent and all, this gives silly issues
4953
return strings.Replace(pwd, "c:", "C:", 1)
5054
}
5155
if env.args != nil && *env.args.PWD != "" {
52-
return correctPath(*env.args.PWD)
56+
env.cwd = correctPath(*env.args.PWD)
57+
return env.cwd
5358
}
5459
dir, err := os.Getwd()
5560
if err != nil {
5661
return ""
5762
}
58-
return correctPath(dir)
63+
env.cwd = correctPath(dir)
64+
return env.cwd
5965
}
6066

6167
func (env *environment) homeDir() string {

0 commit comments

Comments
 (0)