Skip to content

Commit

Permalink
Preserve separator spec on subcommands
Browse files Browse the repository at this point in the history
The separatorSpec is not passed along to the subcommands which means
that SliceFlags on subcommands will not use the global separator
settings.
  • Loading branch information
thschmitt committed Mar 23, 2023
1 parent 560c87b commit 8c9bd3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (c *Command) setup(ctx *Context) {
if scmd.HelpName == "" {
scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name)
}
scmd.separator = c.separator
newCmds = append(newCmds, scmd)
}
c.Subcommands = newCmds
Expand Down
27 changes: 27 additions & 0 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,30 @@ func TestCommand_RunSubcommandWithDefault(t *testing.T) {
err = app.Run([]string{"app"})
expect(t, err, errors.New("should not run this subcommand"))
}

func TestCommand_PreservesSeparatorOnSubcommands(t *testing.T) {
var values []string
subcommand := &Command{
Name: "bar",
Flags: []Flag{
&StringSliceFlag{Name: "my-flag"},
},
Action: func(c *Context) error {
values = c.StringSlice("my-flag")
return nil
},
}
app := &App{
Commands: []*Command{
{
Name: "foo",
Subcommands: []*Command{subcommand},
},
},
SliceFlagSeparator: ";",
}

app.Run([]string{"app", "foo", "bar", "--my-flag", "1;2;3"})

expect(t, values, []string{"1", "2", "3"})
}

0 comments on commit 8c9bd3f

Please sign in to comment.