diff --git a/cmd/internal/exec.go b/cmd/internal/exec.go index 0f97d27..297eba5 100644 --- a/cmd/internal/exec.go +++ b/cmd/internal/exec.go @@ -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) } diff --git a/internal/runner/parallel/parallel.go b/internal/runner/parallel/parallel.go index 0bedfc1..0227c74 100644 --- a/internal/runner/parallel/parallel.go +++ b/internal/runner/parallel/parallel.go @@ -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") } diff --git a/internal/runner/serial/serial.go b/internal/runner/serial/serial.go index d90bb68..ebe3452 100644 --- a/internal/runner/serial/serial.go +++ b/internal/runner/serial/serial.go @@ -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") } diff --git a/internal/templates/templates.go b/internal/templates/templates.go index 564d7f6..430aa38 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go @@ -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") } diff --git a/internal/utils/args/args.go b/internal/utils/args/args.go index ec0c809..8832393 100644 --- a/internal/utils/args/args.go +++ b/internal/utils/args/args.go @@ -1,6 +1,7 @@ package args import ( + "os" "strings" "github.com/jahvon/flow/types/executable" @@ -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 {