more work on env variable parsing

This commit is contained in:
Andrew Woodlee 2024-09-13 20:47:59 -05:00
parent cf04e4456a
commit 51f5084dd0
4 changed files with 17 additions and 4 deletions

View File

@ -4,6 +4,9 @@
"knadh", "knadh",
"koanf", "koanf",
"mattn", "mattn",
"maunium",
"mautrix",
"nikoksr",
"Strs" "Strs"
] ]
} }

View File

@ -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

View File

@ -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()

View File

@ -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
} }
} }
}
} }