spf13 / cobra

A Commander for modern Go CLI interactions
https://cobra.dev
Apache License 2.0
36.88k stars 2.81k forks source link

Override help subcommand logic #2136

Open firelizzard18 opened 2 months ago

firelizzard18 commented 2 months ago

I am using cobra. I don't need subcommands. I do want the default help and completion subcommands to be generated. There should be an option for "generate default subcommands even if no other subcommands are defined".


func (c *Command) InitDefaultHelpCmd() {
    if !c.HasSubCommands() {
        return
    }
    // ...
}

There should be some option that disables the subcommand check.
marckhouzam commented 2 months ago

1559 does this for the completion command.

How would the help command be used in such a case though? The help command is usually used as program help subcommand

firelizzard18 commented 2 months ago

I use program help all the time to print the usage message. Sure, I could use program --help, but it's muscle memory at this point.