From bd93f66304a94db986b0e16b872d63c40563f0ad Mon Sep 17 00:00:00 2001 From: Mohit Panchariya Date: Sun, 15 Mar 2026 14:32:21 +0530 Subject: [PATCH] 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 --- command_run.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/command_run.go b/command_run.go index 676a14c676..c491dd1b16 100644 --- a/command_run.go +++ b/command_run.go @@ -267,13 +267,12 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context subCmd = cmd.Command(name) if subCmd == nil { hasDefault := cmd.DefaultCommand != "" - isFlagName := slices.Contains(cmd.FlagNames(), name) if hasDefault { tracef("using default command=%[1]q (cmd=%[2]q)", cmd.DefaultCommand, cmd.Name) } - if isFlagName || hasDefault { + if hasDefault { argsWithDefault := cmd.argsWithDefaultCommand(cmd.parsedArgs) tracef("using default command args=%[1]q (cmd=%[2]q)", argsWithDefault, cmd.Name) subCmd = cmd.Command(argsWithDefault.First())