We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Expected behavior: command flags should be allowed in front of the commands, even without =true.
=true
func Test_flagsOrder(t *testing.T) { rootCommand := &cobra.Command{SilenceUsage: true, Args: cobra.MaximumNArgs(0)} var flagValue bool rootCommand.PersistentFlags().BoolVar(&flagValue, "rootflag", false, "root boolean flag") cmd := &cobra.Command{Use: "command", SilenceUsage: true, Args: cobra.MaximumNArgs(0)} cmd.PersistentFlags().BoolVar(&flagValue, "cmdflag", false, "command boolean flag") rootCommand.AddCommand(cmd) for name, args := range map[string][]string{ "root flag before command": {"--rootflag", "command"}, // ok "command flag before command": {"--cmdflag", "command"}, // unknown flag: --cmdflag "command flag with =value before command": {"--cmdflag=true", "command"}, // ok } { t.Run(name, func(t *testing.T) { flagValue = false rootCommand.SetArgs(args) if err := rootCommand.Execute(); err != nil { t.Error(err) } if !flagValue { t.Errorf("flag is false") } }) } }
Output:
-- FAIL: Test_flagsOrder (0.00s) --- FAIL: Test_flagsOrder/command_flag_before_command (0.00s) flags_test.go:27: unknown flag: --cmdflag flags_test.go:30: flag is false
The text was updated successfully, but these errors were encountered:
Is it a pflag or cobra issue btw?
Sorry, something went wrong.
roxctl
Moved to cobra.
No branches or pull requests
Expected behavior: command flags should be allowed in front of the commands, even without
=true
.Output:
The text was updated successfully, but these errors were encountered: