Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd93f66

Browse files
Fix 2257 - Remove incorrect flag check
If the argument passed with a command isn't a sub command, there are two checks performed - check if the command has a default command, and check if the argument passed is a flag. In the case that the default command doesn't exist, and the argument passed is the name of a flag, the sub command resolves to nil, which it was previously as well. Implying the check for the flag name doesn't have affect the sub command resolution. Since a default command doesn't exist, the cmd.parsedArgs list ends up with an empty argument as its zeroth element. This commit removes the flag name check
1 parent a107ee4 commit bd93f66

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

command_run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
267267
subCmd = cmd.Command(name)
268268
if subCmd == nil {
269269
hasDefault := cmd.DefaultCommand != ""
270-
isFlagName := slices.Contains(cmd.FlagNames(), name)
271270

272271
if hasDefault {
273272
tracef("using default command=%[1]q (cmd=%[2]q)", cmd.DefaultCommand, cmd.Name)
274273
}
275274

276-
if isFlagName || hasDefault {
275+
if hasDefault {
277276
argsWithDefault := cmd.argsWithDefaultCommand(cmd.parsedArgs)
278277
tracef("using default command args=%[1]q (cmd=%[2]q)", argsWithDefault, cmd.Name)
279278
subCmd = cmd.Command(argsWithDefault.First())

0 commit comments

Comments
 (0)