Skip to content

Commit 8c9bd3f

Browse files
committed
Preserve separator spec on subcommands
The separatorSpec is not passed along to the subcommands which means that SliceFlags on subcommands will not use the global separator settings.
1 parent 560c87b commit 8c9bd3f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (c *Command) setup(ctx *Context) {
135135
if scmd.HelpName == "" {
136136
scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name)
137137
}
138+
scmd.separator = c.separator
138139
newCmds = append(newCmds, scmd)
139140
}
140141
c.Subcommands = newCmds

command_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,30 @@ func TestCommand_RunSubcommandWithDefault(t *testing.T) {
515515
err = app.Run([]string{"app"})
516516
expect(t, err, errors.New("should not run this subcommand"))
517517
}
518+
519+
func TestCommand_PreservesSeparatorOnSubcommands(t *testing.T) {
520+
var values []string
521+
subcommand := &Command{
522+
Name: "bar",
523+
Flags: []Flag{
524+
&StringSliceFlag{Name: "my-flag"},
525+
},
526+
Action: func(c *Context) error {
527+
values = c.StringSlice("my-flag")
528+
return nil
529+
},
530+
}
531+
app := &App{
532+
Commands: []*Command{
533+
{
534+
Name: "foo",
535+
Subcommands: []*Command{subcommand},
536+
},
537+
},
538+
SliceFlagSeparator: ";",
539+
}
540+
541+
app.Run([]string{"app", "foo", "bar", "--my-flag", "1;2;3"})
542+
543+
expect(t, values, []string{"1", "2", "3"})
544+
}

0 commit comments

Comments
 (0)