Skip to content

Commit 0436998

Browse files
authored
Merge pull request #1710 from thschmitt/fix/subcommand-separator
Preserve separator spec on subcommands
2 parents 560c87b + 8c9bd3f commit 0436998

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

command.go

+1
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

+27
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)