Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve separator spec on subcommands #1710

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
dearchap marked this conversation as resolved.
Show resolved Hide resolved
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"})
}