Skip to content
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

Add AppSettings to disable automatic "help" subcommand #787

Closed
Xion opened this issue Dec 27, 2016 · 4 comments
Closed

Add AppSettings to disable automatic "help" subcommand #787

Xion opened this issue Dec 27, 2016 · 4 comments
Assignees
Labels
C-bug Category: Updating dependencies
Milestone

Comments

@Xion
Copy link

Xion commented Dec 27, 2016

When using SubCommands, clap will automatically include a "help" subcommand:

SUBCOMMANDS:
    help     Prints this message or the help of the given subcommand(s)

This is redundant, as subcommand help can also be obtained via $SUBCOMMAND --help.

Right now, it seems there is no way to hide that superfluous subcommand, as this doesn't work:

app.subcommand(SubCommand::with_name("help").setting(AppSettings::Hidden))

Consequently, the "help" subcommand may have to be handled explicitly.

Suggestion: introduce AppSettings::NoHelpSubcommand which, if set on the root App, hides the "help" subcommand from usage output.

@kbknapp
Copy link
Member

kbknapp commented Dec 27, 2016

Interesting, the fact that

app.subcommand(SubCommand::with_name("help").setting(AppSettings::Hidden))

Isn't hiding the subcommand looks like a bug. I'll dig into this further, because that's the intended behavior, and I would prefer that to an AppSettings::NoHelpSubcommand.

Also, small note, the help subcommand does a little more than the --help flag. It allows pulling the help from arbitrary other subcommands as well.

For instance, the following invocations are equivalent:

$ prog help push
$ prog push --help

$ prog help subcmd othercmd
$ prog subcmd othercmd --help

$ prog help
$ prog --help

@kbknapp kbknapp added C: subcommands C-bug Category: Updating dependencies labels Dec 27, 2016
@kbknapp kbknapp added this to the 2.20.0 milestone Dec 27, 2016
@Xion
Copy link
Author

Xion commented Dec 28, 2016

For the record, I'm also using UnifiedHelpMessage. Not sure if it affects this.

What's also curious is that "help" subcommand is actually gone from the output of App::write_help, but it's there in the Err from App::get_matches_safe (so probably also in the stdout output of regular App::get_matches) called against empty argv, or argv with just help.

@kbknapp
Copy link
Member

kbknapp commented Dec 28, 2016

UnifiedHelpMessage shouldn't affect it at all. The part about being missing from write_help I'm assuming --help and --version are missing too. This is because unless a parsing method was calld (get_matches_*) those arguments and subcommands aren't built yet, since they're built lazily to allow users to override them (which is why this is a bug 😉)

@kbknapp kbknapp self-assigned this Dec 31, 2016
@kbknapp
Copy link
Member

kbknapp commented Dec 31, 2016

I have this fixed in a local branch and will upload shortly. You can now either do as you were, Subcommand::with_name("help").setting(AppSettings::Hidden)) or use the new setting app.setting(AppSettings::DisableHelpSubcommand). The benefit of using the new setting is it actually disables the subcommand entirely, not just hides it. Also you can make it a global setting, and it will disable the help subcommand of all child subcommands as well.

kbknapp added a commit that referenced this issue Dec 31, 2016
@homu homu closed this as completed in d34ec3e Dec 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants