Closed
Description
I have a subcommand that has no Run function.
var containerCmd = &cobra.Command{
Use: "container",
Short: "Global settings for running containers",
}
func init() {
configCmd.AddCommand(containerCmd)
containerCmd.PersistentFlags().String("networkEndpoint", "", "Specify a network endpoint (in case you need to network between containers)")
viper.BindPFlag("networkEndpoint", containerCmd.PersistentFlags().Lookup("networkEndpoint"))
}
...
It only shows the usage when it's added to the rootCmd. When it is not, it only shows the short description. It won't show the help even if I pass the --help flag
. It should show the usage when I pass the help flag or no arguments.
I noticed two things:
- Cobra returns "help requested" if the command is not runnable
Lines 724 to 726 in fe5e611
- Cobra only renders the Usage if the command is runnable
Lines 432 to 434 in fe5e611
I added HasFlags
to this template and it always displays the usage.
It might be related to #206 (comment)
Metadata
Metadata
Assignees
Labels
No labels