Skip to content

Commit 852060e

Browse files
committed
Fix issue: 2257 Next arg flag name, no default cmd
If the next argument matches a flag name, and there is no default command, a spurious empty string gets inserted before the flag name. Existing code that expects the flag name in element 0 fails because it is now in element 1 with an empty string in element 0. When there is no default command and an empty string is detected in element 0 (i.e. `cmd.parsedArgs.First()`), change `cmd.parsedArgs` to omit the first empty element.
1 parent fd14621 commit 852060e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

command_run.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
274274
tracef("using default command args=%[1]q (cmd=%[2]q)", argsWithDefault, cmd.Name)
275275
subCmd = cmd.Command(argsWithDefault.First())
276276
cmd.parsedArgs = argsWithDefault
277+
if !hasDefault && cmd.parsedArgs.Len() > 0 && cmd.parsedArgs.First() == "" {
278+
&stringSliceArgs{cmd.parsedArgs.Tail()}
279+
}
277280
}
278281
}
279282
} else if cmd.DefaultCommand != "" {

0 commit comments

Comments
 (0)