diff --git a/command.go b/command.go index f978b4a43e..69a0fdf6dc 100644 --- a/command.go +++ b/command.go @@ -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 diff --git a/command_test.go b/command_test.go index 53ca54bd21..d6e40c9a27 100644 --- a/command_test.go +++ b/command_test.go @@ -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"}) +}