From 8c9bd3f0503ee6419bd1e87738b446b66064b1a1 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 23 Mar 2023 11:38:05 +0200 Subject: [PATCH] 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. --- command.go | 1 + command_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) 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"}) +}