-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed as not planned
Labels
area/flags-argsChanges to functionality around command line flags and argsChanges to functionality around command line flags and argslifecycle/needs-prReady for a PR from the communityReady for a PR from the community
Description
I expected this to be the default behaviour but maybe there's a good argument for how it is today.
If you add a command with DisableFlagParsing, then help cmd
will list -h
as a flag, but running cmd -h
will not print the help, it'll invoke Run() with ['-h']. If it's the command's responsibility to parse all of the flags, I think it makes sense to not add flags automatically.
Here is a simplified example:
package main
import "github.com/spf13/cobra"
func main() {
cmd := &cobra.Command{
Use: "root",
TraverseChildren: true,
}
sub := &cobra.Command{
Use: "sub",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {},
}
cmd.AddCommand(sub)
cmd.SetArgs([]string{"help", "sub"})
cmd.Execute()
}
The output is:
Usage:
root sub [flags]
Flags:
-h, --help help for sub
Is there any better way to disable this help flag than this?
sub.InitDefaultHelpFlag()
sub.Flags().MarkHidden("help")
Metadata
Metadata
Assignees
Labels
area/flags-argsChanges to functionality around command line flags and argsChanges to functionality around command line flags and argslifecycle/needs-prReady for a PR from the communityReady for a PR from the community