-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Have help
subcommand show help for other subcommands
#416
Comments
Thanks for taking the time to file this! This was actually a by-design decision. What you're looking for is implemented in reverse, i.e. These two are identical
While it would be possible to implement a setting to switch this, or allow switching to
But I'd prefer that be an opt-in setting and not the default. This is what I'm thinking of in order to implement what you're talking about: extern crate clap;
use clap::{App, AppSettings, SubCommand};
fn main() {
App::new("cargo")
.setting(AppSettings::SubcommandRequiredElseHelp)
.setting(AppSettings::ReverseHelpSubcommand)
.about("Rust's mock package manager")
.subcommand(SubCommand::with_name("build")
.about("Compile the current project")
.after_help("This is a mock cargo-build command.\nNot real."))
.get_matches();
} The downside to this that while matching, once We would also need to implement an appropriate error in case someone did
Which now that I'm thinking out loud about it would be simple - if I'll mark this as new-setting, and play with some implementations. Thanks again 👍 |
Other names for settings could be Because what I imagine (and I'd be curious to hear your input) would be that the top level i.e. Imagine the following fictional subcommand structure
Or would you expect something like
|
Wouldn't that cause ambiguities if there are multiple subcommands of the same name? e.g.
Another problem with postfix help subcommand is that subcommands can take positional arguments. e.g. |
Yes, you're correct option 1 wouldn't work. I realized that after posting it. Post fix such as I do however like the option of adding option 2 as an opt-in setting (only because the default is already set to postfix and changing it would be a breaking change). So |
|
@Fiedzia that is an internal setting which isn't really intended to be used by end users. I have a few other features to implement as well as this one, but I do plan on adding another setting to give the desired effect you're looking for 😉 Subscribe to this issue for updates on the feature. |
… help subcommand The `help` subcommand can now accept other subcommands as arguments to display their help message. This is similar to how many other CLIs already perform. For example: ``` $ myprog help mysubcmd ``` Would print the help message for `mysubcmd`. But even more, the `help` subcommand accepts nested subcommands as well, i.e. a grandchild subcommand such as ``` $ myprog help child grandchild ``` Would print the help message of `grandchild` where `grandchild` is a subcommand of `child` and `child` is a subcommand of `myprog`. Closes #416
Right now, the auto generated help subcommand seems to ignore trailing arguments, even if
they are names of other subcommands.
What I expect is that it would show the help for the subcommand provided as an argument.
This is how for example Cargo (
cargo help build
) or Git (git help commit
) work.Example
A simple mock cargo
Help invocation
I want to know more about the build subcommand. The instinctive action is to invoke help with the subcommand name as the argument.
Strange. It just prints the same thing as before.
What I expect to happen instead:
If possible, it would be nice if it would error if an invalid subcommand was provided as an argument.
Cargo example:
The text was updated successfully, but these errors were encountered: