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

short version of help is not overridden anymore #4304

Closed
2 tasks done
erazor-de opened this issue Sep 30, 2022 · 2 comments
Closed
2 tasks done

short version of help is not overridden anymore #4304

erazor-de opened this issue Sep 30, 2022 · 2 comments
Labels
C-bug Category: Updating dependencies

Comments

@erazor-de
Copy link

erazor-de commented Sep 30, 2022

Please complete the following tasks

Rust Version

rustc 1.64.0 (a55dd71d5 2022-09-19)

Clap Version

4.0.6

Minimal reproducible code

[package]
name = "claptest"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4", features = ["derive"] }
use clap::Parser;

#[derive(Parser)]
pub struct Args {
    #[arg(short, long)]
    pub hyperlink: bool,
}

fn main() {
    let _args = Args::parse();
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

Panicks with following message:

thread 'main' panicked at 'Command claptest: Short option names must be unique for each argument, but '-h' is in use by both 'hyperlink' and 'help' (call cmd.disable_help_flag(true) to remove the auto-generated --help)', /home/stefan/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-4.0.6/src/builder/debug_asserts.rs:121:17

Expected Behaviour

clap version 3 removed the short help '-h' when another arg used it.

Additional Context

No response

Debug Output

[      clap::builder::command]  Command::_do_parse
[      clap::builder::command]  Command::_build: name="claptest"
[      clap::builder::command]  Command::_propagate:claptest
[      clap::builder::command]  Command::_check_help_and_version:claptest expand_help_tree=false
[      clap::builder::command]  Command::long_help_exists
[      clap::builder::command]  Command::_check_help_and_version: Building default --help
[      clap::builder::command]  Command::_propagate_global_args:claptest
[clap::builder::debug_asserts]  Command::_debug_asserts
[clap::builder::debug_asserts]  Arg::_debug_asserts:hyperlink
thread 'main' panicked at 'Command claptest: Short option names must be unique for each argument, but '-h' is in use by both 'hyperlink' and 'help' (call `cmd.disable_help_flag(true)` to remove the auto-generated `--help`)', /home/stefan/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-4.0.6/src/builder/debug_asserts.rs:121:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@erazor-de erazor-de added the C-bug Category: Updating dependencies label Sep 30, 2022
@shepmaster
Copy link
Contributor

The section "Removing Implicit Version/Help Behavior" in clap 4.0, a Rust CLI argument parser may be relevant.

@epage
Copy link
Member

epage commented Sep 30, 2022

Yes,. this was an intentional change and the above linked blog post provides a summary of it and why.

We covered parts of the change in the CHANGELOG,

mut_arg can no longer be used to customize help and version arguments, instead disable them (Command::disable_help_flag, Command::disable_version_flag) and provide your own (#4056)

and

Arg::new("help") and Arg::new("version") no longer implicitly disable the built-in flags and be copied to all subcommands, instead disable the built-in flags (Command::disable_help_flag, Command::disable_version_flag) and mark the custom flags as global(true). (#4056)

but we seemed to have not explicitly called out this aspect of it. That has no been rectified.

As this is expected behavior and (now) documented, I'm closing this out.

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

3 participants