-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
short -h
conflicts with help rather than overwriting it
#3403
Comments
I was wrong with this comment, click to expand if you want to see how I was wrong.My best guess:
(side note: wow that debug flag is cool!) It appears to remove the generated version, but not the generated help. Lines 2915 to 2924 in 7ca872e
vs Lines 2873 to 2881 in 7ca872e
by diffing the two, it seems that the difference is version has
but help does not! (also: one has |
btw a slightly simpler reproduction case use clap::IntoApp;
use clap::Parser;
#[derive(Parser)]
#[clap(name = "command")]
pub struct Args {
#[clap(subcommand)]
pub cmd: Subcommand,
}
#[derive(Parser)]
pub enum Subcommand {
#[clap(external_subcommand)]
Other(Vec<String>),
Subcommand {
#[clap(short)]
hold: bool,
},
}
fn main() {
let _m = Args::parse();
} |
The goal isn't to remove help but to not set the short. This is the relevant section of code let other_arg_has_short = self.args.args().any(|x| x.short == Some('h'));
let help = self
.args
.args_mut()
.find(|x| x.id == Id::help_hash())
.expect(INTERNAL_ERROR_MSG);
if !(help.short.is_some()
|| other_arg_has_short
|| self.subcommands.iter().any(|sc| sc.short_flag == Some('h')))
{
help.short = Some('h');
} |
We aren't setting |
Ok, so I can detect this case and remove
My question is "should we change this?". Not from an implementation perspective but a user perspective. This will only be hit when a child subcommand has a Granted, we don't do anything else in clap to enforce consistency but I think "help" and "version' are a little different in that regard. Thoughts? |
There's also the third option, which is "do nothing but document this in the documentation for short" :) To be honest, I have no strong opinions about how clap handles this case; personally, I would never add in a
I agree! But also talking to some folks, I think it might be more subtle than that. When discussing this behavior with the rest of the folks involved some people apparently only think of A tough choice! I also agree that |
For now, we are going to provide a better debug assert in this case. Resolving clap-rs#3405 is the better long term route. Fixes clap-rs#3403
Sorry, I'm a bit late to this conversation. I just discovered this issue when updating an CLI at $DAYJOB from clap 2.34.0 to 3.1.6.
This seems a little over-opinionated. Especially considering existing clap v2 apps where "-h" or "-h foo" mean something else for some of their subcommands; expecting/requiring devs change their app's subcommand's arguments is even more likely to violate their user's expectations.
This is true in my case. To address the consistency / confusion issue, I'd be happy with something like a Command::disable_short_help_flag() to disable just '-h'. |
This change surprised me and broke my code that previously worked with structopt, and which worked for every other subcommand except one which panics at run time. Not a good experience at all, for the developer or user. Many applications, including git, only use --help and not -h, so this does seem like an unnecessary restriction. |
Please complete the following tasks
Rust Version
1.57.0
Clap Version
3.0.14
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run -- subcommand -h
Actual Behaviour
Expected Behaviour
Additional Context
#3400 (comment)
Because this is a debug assertion that fails, running with
--release
gives the expected behavior, which is what initially caused this bug to go unnoticed for a while.I know that this setup might be slightly weird, this is an app I didn't originally write and there's a comment block:
I recently ported this app from structopt/clapv2 to clap v3; it's possible that this comment is now irrelevant but I haven't investigated that yet.
Debug Output
The text was updated successfully, but these errors were encountered: