cobra
cobra copied to clipboard
Fix unexpected executing subcommand
I've defined a subcommand with two boolean arguments and found it unexpectedly run into the subcommand. In specific, a subcommand naming "sub" with two boolean arguments "a" and "b". If I parse the command with arguments " --a sub" or "--b sub", it returns an "unknown argument" error as expected. But when I parse the command with arguments "--a --b sub", it unexpectedly runs into the "sub" command with those two boolean arguments set.
I trace down the codes in cobra and find that stripFlags
always assume the pattern of flags is'--flag arg'
or '-f arg'
, ignoring the pattern of a boolean flag('--bflag'
). So I file a PR trying to fix this unexpected behavior.
Thanks @JaySon-Huang! I can reproduce the problem. I haven't looked at the fix yet, but we will need to be very careful not to break anything.
@marckhouzam sure. I add some comments on the code to make my assumptions more clear. Feel free to leave any comments when you are free.
This PR is being marked as stale due to a long period of inactivity