urfave / cli

A simple, fast, and fun package for building command line apps in Go
https://cli.urfave.org
MIT License
22.29k stars 1.7k forks source link

--help/-h only in GLOBAL OPTIONS? #1989

Open decentral1se opened 13 hours ago

decentral1se commented 13 hours ago

Checklist

What problem does this solve?

--help/-h appears in both options/global options for sub-commands and that is noisy.

Solution description

Support only specifying --help/-h as a global option.

Describe alternatives you've considered

There is currently a (potentially unknown?) hack to make this work. What you need to do:

Set cli.Help on your root command (otherwise you get Incorrect Usage: flag: help requested error):

    cli.HelpFlag = &cli.BoolFlag{
        Name:    "help",
        Aliases: []string{"h, H"},
        Usage:   "Show help",
    }

Then set HideHelpCommand: true on the root command.

Then set HideHelp: true on all sub-commands.

Then --help/-h only appears in GLOBAL OPTIONS and not OPTIONS and you do not receive the Incorrect Usage: flag: help requested error.

decentral1se commented 12 hours ago

There is an additional inconsistency that sub-commands that are not leaf commands show --help/-h in OPTIONS regardless of the above hack. And HideHelp: true then actually hides the flag.