Skip to content

Commit

Permalink
fancier variable interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Dec 30, 2023
1 parent 49c96b5 commit bea62ad
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion common/os_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/mitchellh/go-homedir"
"go.spiff.io/expand"
)

type OsFilesystem struct{}
Expand All @@ -19,7 +20,7 @@ func (*OsFilesystem) GetAbsolutePath(path string) string {
if err == nil {
path = absPath
}
return os.ExpandEnv(path)
return expand.Expand(path, os.LookupEnv)
}

// returns (exists, isDir)
Expand Down
2 changes: 1 addition & 1 deletion common/os_filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func getEnvVarPath() string {
if runtime.GOOS == "windows" {
return "%" + interpolatedVar + "%"
}
return fmt.Sprintf("${%s}", interpolatedVar)
return fmt.Sprintf("${%s:-shouldNotMatter}", interpolatedVar)
}

func createTempFile(t *testing.T) *os.File {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/zyedidia/generic v1.2.1
go.spiff.io/expand v1.1.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/zyedidia/generic v1.2.1 h1:Zv5KS/N2m0XZZiuLS82qheRG4X1o5gsWreGb0hR7XDc=
github.com/zyedidia/generic v1.2.1/go.mod h1:ly2RBz4mnz1yeuVbQA/VFwGjK3mnHGRj1JuoG336Bis=
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4=
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
go.spiff.io/expand v1.1.0 h1:DseUwDcllRql2XIgEAepsodeCSBPul2fTrKpwswCR1I=
go.spiff.io/expand v1.1.0/go.mod h1:HtW3QveGpZ/RGJ2KtOdFrJsb/0aFYi69AoBnN+YRFAc=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
Expand Down

0 comments on commit bea62ad

Please sign in to comment.