-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
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
Unknown commands '-h' and '--help' #63
Comments
This seems to be the case with all "global" flags, and I suspect this has actually never worked. It doesn't work for 10a8494 which introduced support for flags before commands. Basically, it looks like if there are no commands present, it never gets to the flag parsing phase. I wanted to be able to follow certain conventions wrt You can workaround this in your code presently: rootCmd.ParseFlags(os.Args)
rootFlags := rootCmd.Flags()
rootFlags.Visit(func(flag *pflag.Flag) {
if flag.Name == "help" {
fmt.Println(rootCmd.Long)
rootCmd.Usage()
os.Exit(-1)
}
})
rootCmd.Execute() I thought about trying to do a PR for this but it doesn't look straightforward to fix. Update: For whatever reason, |
@eparis as of the latest commit, -h was removed from the help template output. Was this intentional or related to this? |
it certainly possible i screwed it up and --help disappeared from the help output... |
I just built a sample cobra for the first time, and ran into the -h doesn't work but also noticed it wasn't there so I was trying to figure out how to add it. |
Nvm @eparis pebcak. |
I am not seeing this issue as of the latest build. |
Confirmed. Fixed in latest build. Closing. |
Using the default example with 'Short' & 'Long' added to rootCmd:
Output of
app
andapp help
is correct and lists '-h' and '--help' as global flags:app -h
andapp --help
fail with 'unknown command':The text was updated successfully, but these errors were encountered: