Skip to content

Commit

Permalink
replacer: working directory global placeholder (#5127)
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Oct 7, 2022
1 parent d46ba2e commit b4e28af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions replacer.go
Expand Up @@ -308,6 +308,10 @@ func globalDefaultReplacements(key string) (any, bool) {
return string(filepath.Separator), true
case "system.os":
return runtime.GOOS, true
case "system.wd":
// OK if there is an error; just return empty string
wd, _ := os.Getwd()
return wd, true
case "system.arch":
return runtime.GOARCH, true
case "time.now":
Expand Down
5 changes: 5 additions & 0 deletions replacer_test.go
Expand Up @@ -372,6 +372,7 @@ func TestReplacerNew(t *testing.T) {
} else {
// test if default global replacements are added as the first provider
hostname, _ := os.Hostname()
wd, _ := os.Getwd()
os.Setenv("CADDY_REPLACER_TEST", "envtest")
defer os.Setenv("CADDY_REPLACER_TEST", "")

Expand All @@ -395,6 +396,10 @@ func TestReplacerNew(t *testing.T) {
variable: "system.arch",
value: runtime.GOARCH,
},
{
variable: "system.wd",
value: wd,
},
{
variable: "env.CADDY_REPLACER_TEST",
value: "envtest",
Expand Down

0 comments on commit b4e28af

Please sign in to comment.