Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions command_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context

for _, flag := range cmd.allFlags() {
isSet := flag.IsSet()
// Propagate the command's slice/map separator config before PostParse
// so that env-var values are split with the same separator as CLI
// values (see https://github.com/urfave/cli/issues/2262).
cmd.setMultiValueParsingConfig(flag)
if err := flag.PostParse(); err != nil {
return ctx, err
}
Expand Down
22 changes: 22 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4590,6 +4590,28 @@ func TestCommandSliceFlagSeparator(t *testing.T) {
r.Equal([]string{"ff", "dd", "gg", "t,u"}, cmd.Value("foo"))
}

// TestCommandSliceFlagSeparatorFromEnvVar is a regression test for
// https://github.com/urfave/cli/issues/2262.
// SliceFlagSeparator must be respected when flag values come from env vars,
// not only when they are supplied on the command line.
func TestCommandSliceFlagSeparatorFromEnvVar(t *testing.T) {
t.Setenv("FOO", "ff;dd;gg")

cmd := &Command{
SliceFlagSeparator: ";",
Flags: []Flag{
&StringSliceFlag{
Name: "foo",
Sources: EnvVars("FOO"),
},
},
}

r := require.New(t)
r.NoError(cmd.Run(buildTestContext(t), []string{"app"}))
r.Equal([]string{"ff", "dd", "gg"}, cmd.Value("foo"))
}

func TestCommandMapKeyValueFlagSeparator(t *testing.T) {
cmd := &Command{
MapFlagKeyValueSeparator: ":",
Expand Down