Skip to content

Commit

Permalink
Merge pull request #440 from Kuniwak/fix-json-env
Browse files Browse the repository at this point in the history
`--env` no longer takes comma-separated arguments; it treats the whole string as one `a=b` assignment. Note that you can still pass in multiple env vars by using the `--env` flag multiple times.
  • Loading branch information
aengelberg authored Sep 9, 2020
2 parents 8558e75 + 4379e22 commit a8361bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func AddFlagsForDocumentation(flags *pflag.FlagSet) {
flags.String("revision", "", "Git Revision")
flags.String("branch", "", "Git branch")
flags.String("repo-url", "", "Git Url")
flags.StringSliceP("env", "e", nil, "Set environment variables, e.g. `-e VAR=VAL`")
flags.StringArrayP("env", "e", nil, "Set environment variables, e.g. `-e VAR=VAL`")
}

// Given the full set of flags that were passed to this command, return the path
Expand Down Expand Up @@ -308,7 +308,7 @@ func unparseFlag(flags *pflag.FlagSet, flag *pflag.Flag) []string {
switch flag.Value.Type() {
// A stringArray type argument is collapsed into a single flag:
// `--foo 1 --foo 2` will result in a single `foo` flag with an array of values.
case "stringSlice":
case "stringArray":
for _, value := range flag.Value.(pflag.SliceValue).GetSlice() {
result = append(result, flagName, value)
}
Expand Down
6 changes: 6 additions & 0 deletions local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ var _ = Describe("build", func() {
expectedArgs: []string{"--env", "foo", "--env", "bar", "--env", "baz"},
}),

Entry("comma in env value (issue #440)", TestCase{
input: []string{"--env", "{\"json\":[\"like\",\"value\"]}"},
expectedConfigPath: ".circleci/config.yml",
expectedArgs: []string{"--env", "{\"json\":[\"like\",\"value\"]}"},
}),

Entry("args that are not flags", TestCase{
input: []string{"a", "--debug", "b", "--config", "foo", "d"},
expectedConfigPath: "foo",
Expand Down

0 comments on commit a8361bf

Please sign in to comment.