Skip to content

Commit

Permalink
feat: expand environment variables in ref config arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jahvon committed Oct 11, 2024
1 parent c50e5a0 commit 2fc6ab0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/internal/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func execFunc(ctx *context.Context, cmd *cobra.Command, verb executable.Verb, ar
}

execArgs := args[1:]
envMap, err := argUtils.ProcessArgs(e, execArgs)
envMap, err := argUtils.ProcessArgs(e, execArgs, nil)
if err != nil {
logger.FatalErr(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/parallel/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func handleExec(
execPromptedEnv := make(map[string]string)
maps.Copy(promptedEnv, execPromptedEnv)
if len(refConfig.Args) > 0 {
a, err := argUtils.ProcessArgs(exec, refConfig.Args)
a, err := argUtils.ProcessArgs(exec, refConfig.Args, execPromptedEnv)
if err != nil {
ctx.Logger.Error(err, "unable to process arguments")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/serial/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func handleExec(
execPromptedEnv := make(map[string]string)
maps.Copy(promptedEnv, execPromptedEnv)
if len(refConfig.Args) > 0 {
a, err := argUtils.ProcessArgs(exec, refConfig.Args)
a, err := argUtils.ProcessArgs(exec, refConfig.Args, execPromptedEnv)
if err != nil {
ctx.Logger.Error(err, "unable to process arguments")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func runExecutables(
}
args = append(args, a.String())
}
a, err := argUtils.ProcessArgs(exec, args)
a, err := argUtils.ProcessArgs(exec, args, envMap)
if err != nil {
ctx.Logger.Error(err, "unable to process arguments")
}
Expand Down
15 changes: 14 additions & 1 deletion internal/utils/args/args.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package args

import (
"os"
"strings"

"github.com/jahvon/flow/types/executable"
Expand All @@ -20,7 +21,19 @@ func ParseArgs(args []string) (flagArgs map[string]string, posArgs []string) {
return
}

func ProcessArgs(executable *executable.Executable, execArgs []string) (map[string]string, error) {
func ProcessArgs(
executable *executable.Executable,
execArgs []string,
env map[string]string,
) (map[string]string, error) {
if env != nil {
// Expand environment variables in arguments
for i, a := range execArgs {
execArgs[i] = os.Expand(a, func(key string) string {
return env[key]
})
}
}
flagArgs, posArgs := ParseArgs(execArgs)
execEnv := executable.Env()
if execEnv == nil || execEnv.Args == nil {
Expand Down

0 comments on commit 2fc6ab0

Please sign in to comment.