more work on env variable parsing
This commit is contained in:
parent
cf04e4456a
commit
51f5084dd0
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -4,6 +4,9 @@
|
|||||||
"knadh",
|
"knadh",
|
||||||
"koanf",
|
"koanf",
|
||||||
"mattn",
|
"mattn",
|
||||||
|
"maunium",
|
||||||
|
"mautrix",
|
||||||
|
"nikoksr",
|
||||||
"Strs"
|
"Strs"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -103,7 +103,7 @@ May be `scriptFile` or `script`. Runs script from local machine on remote host p
|
|||||||
|
|
||||||
If `type` is `script`, `cmd` is used as the script.
|
If `type` is `script`, `cmd` is used as the script.
|
||||||
|
|
||||||
If `type` is `scriptFile`, cmd must be a file path.
|
If `type` is `scriptFile`, cmd must be a script file.
|
||||||
|
|
||||||
### environment
|
### environment
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ var homeDirErr error
|
|||||||
var backyHomeConfDir string
|
var backyHomeConfDir string
|
||||||
var configFiles []string
|
var configFiles []string
|
||||||
|
|
||||||
|
const macroStart string = "%{"
|
||||||
|
const macroEnd string = "}%"
|
||||||
|
const envMacroStart string = "%{env:"
|
||||||
|
const vaultMacroStart string = "%{env:"
|
||||||
|
|
||||||
func (opts *ConfigOpts) InitConfig() {
|
func (opts *ConfigOpts) InitConfig() {
|
||||||
|
|
||||||
homeDir, homeDirErr = os.UserHomeDir()
|
homeDir, homeDirErr = os.UserHomeDir()
|
||||||
|
@ -221,10 +221,15 @@ func expandEnvVars(backyEnv map[string]string, envVars []string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse env variables using new macros
|
||||||
for indx, v := range envVars {
|
for indx, v := range envVars {
|
||||||
if strings.Contains(v, "$") || (strings.Contains(v, "${") && strings.Contains(v, "}")) {
|
if strings.HasPrefix(v, macroStart) && strings.HasSuffix(v, macroEnd) {
|
||||||
|
if strings.HasPrefix(v, envMacroStart) {
|
||||||
|
v = strings.TrimPrefix(v, envMacroStart)
|
||||||
|
v = strings.TrimRight(v, macroEnd)
|
||||||
out, _ := shell.Expand(v, env)
|
out, _ := shell.Expand(v, env)
|
||||||
envVars[indx] = out
|
envVars[indx] = out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user