Skip to content

Commit

Permalink
Merge pull request #1710 from thschmitt/fix/subcommand-separator
Browse files Browse the repository at this point in the history
Preserve separator spec on subcommands
  • Loading branch information
meatballhat authored Mar 26, 2023
2 parents 560c87b + 8c9bd3f commit 0436998
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 0436998

Please sign in to comment.