Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --env/-e flag to fn run #2988

Merged
merged 1 commit into from Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/config/internal/commands/run-fns.go
Expand Up @@ -69,6 +69,9 @@ func GetRunFnRunner(name string) *RunFnRunner {
"a list of storage options read from the filesystem")
r.Command.Flags().BoolVar(
&r.LogSteps, "log-steps", false, "log steps to stderr")
r.Command.Flags().StringArrayVarP(
&r.Env, "env", "e", []string{},
"a list of environment variables to be used by functions")
return r
}

Expand Down Expand Up @@ -96,6 +99,7 @@ type RunFnRunner struct {
NetworkName string
Mounts []string
LogSteps bool
Env []string
}

func (r *RunFnRunner) runE(c *cobra.Command, args []string) error {
Expand Down Expand Up @@ -311,6 +315,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
StorageMounts: storageMounts,
ResultsDir: r.ResultsDir,
LogSteps: r.LogSteps,
Env: r.Env,
}

// don't consider args for the function
Expand Down
13 changes: 13 additions & 0 deletions cmd/config/internal/commands/run_test.go
Expand Up @@ -204,6 +204,7 @@ apiVersion: v1
Path: "dir",
NetworkName: "bridge",
EnableStarlark: true,
Env: []string{},
},
},
{
Expand Down Expand Up @@ -257,6 +258,7 @@ apiVersion: v1
Path: "dir",
NetworkName: "bridge",
ResultsDir: "foo/",
Env: []string{},
},
expected: `
metadata:
Expand Down Expand Up @@ -292,6 +294,17 @@ apiVersion: v1
Path: "dir",
NetworkName: "bridge",
LogSteps: true,
Env: []string{},
},
},
{
name: "envs",
args: []string{"run", "dir", "--env", "FOO=BAR", "-e", "BAR"},
path: "dir",
expectedStruct: &runfn.RunFns{
Path: "dir",
NetworkName: "bridge",
Env: []string{"FOO=BAR", "BAR"},
},
},
}
Expand Down