-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
A-builderArea: Builder APIArea: Builder APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsE-mediumCall for participation: Experience needed to fix: Medium / intermediateCall for participation: Experience needed to fix: Medium / intermediateM-breaking-changeMeta: Implementing or merging this will introduce a breaking change.Meta: Implementing or merging this will introduce a breaking change.
Milestone
Description
Maintainer's notes
- We'd remove the pre-generated help / version arguments
- Instead we'd add a version and help flag if needed.
- This makes it so we have one way to customize
- We'd switch to an
Action
system where you set an arguments action toAction::Set
,Action::Extend
,Action::SetTrue
,Action::Count
, etc. The ones relevant here would beAction::Help
andAction::Version
.- We'd default arguments to
Action::Set
orAction::SetTrue
(depending on other settings) unless they were namedversion
orhelp
for which we'd default their actions toAction::Help
andAction::Version
- We can leverage Actions for also giving users control over short vs long help
- We'd default arguments to
Original title: "cannot have an option named "version""
- See
#[clap(global_setting(AppSettings::NoAutoVersion))]
for solving that
Please complete the following tasks
- I have searched the discussions
- I have searched the existing issues
Rust Version
rustc 1.59.0-nightly (34926f0a1 2021-12-22)
Clap Version
3.0.14
Minimal reproducible code
use clap::Parser;
#[derive(Parser)]
#[clap(name = "foobar")]
pub struct Args {
/// verbose messages
#[clap(long, short)]
pub verbose: bool,
/// version the thing
#[clap(long, short = 'x')]
pub version: bool,
}
fn main() {
let args = Args::parse();
println!("verbose is {:?}, version is {:?}", args.verbose, args.version);
}
Steps to reproduce the bug with the above code
cargo run -- -x
or cargo run -- --version
Actual Behaviour
foobar
Expected Behaviour
verbose is false, version is true
Additional Context
We need to have a --version
option that does more than the Clap default. Currently, Clap special-cases the string version
, and seemingly overrides its behavior (changing the option name to anything else results in the expected behavior). This seems to be a version
manifestation of behavior similar to #3403.
Debug Output
[ clap::build::app] App::_do_parse
[ clap::build::app] App::_build
[ clap::build::app] App::_propagate:foobar
[ clap::build::app] App::_check_help_and_version
[ clap::build::app] App::_check_help_and_version: Removing generated version
[ clap::build::app] App::_propagate_global_args:foobar
[ clap::build::app] App::_derive_display_order:foobar
[clap::build::app::debug_asserts] App::_debug_asserts
[clap::build::arg::debug_asserts] Arg::_debug_asserts:help
[clap::build::arg::debug_asserts] Arg::_debug_asserts:verbose
[clap::build::arg::debug_asserts] Arg::_debug_asserts:version
[clap::build::app::debug_asserts] App::_verify_positionals
[ clap::parse::parser] Parser::get_matches_with
[ clap::parse::parser] Parser::get_matches_with: Begin parsing 'RawOsStr("--version")' ([45, 45, 118, 101, 114, 115, 105, 111, 110])
[ clap::parse::parser] Parser::get_matches_with: Positional counter...1
[ clap::parse::parser] Parser::get_matches_with: Low index multiples...false
[ clap::parse::parser] Parser::possible_subcommand: arg=RawOsStr("--version")
[ clap::parse::parser] Parser::get_matches_with: sc=None
[ clap::parse::parser] Parser::parse_long_arg
[ clap::parse::parser] Parser::parse_long_arg: cur_idx:=1
[ clap::parse::parser] Parser::parse_long_arg: Does it contain '='...
[ clap::parse::parser] No
[ clap::parse::parser] Parser::parse_long_arg: Found valid opt or flag '--version'
[ clap::parse::parser] Parser::check_for_help_and_version_str
[ clap::parse::parser] Parser::check_for_help_and_version_str: Checking if --RawOsStr("version") is help or version...
[ clap::parse::parser] Version
[ clap::parse::parser] Parser::get_matches_with: After parse_long_arg VersionFlag
[ clap::parse::parser] Parser::version_err
[ clap::build::app] App::_render_version
[ clap::build::app] App::color: Color setting...
[ clap::build::app] Auto
foobar
The debug output is very helpful about indicating what it's doing, it's just that this is behavior that we do not want.
schneiderfelipe and Creative-Difficulty
Metadata
Metadata
Assignees
Labels
A-builderArea: Builder APIArea: Builder APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsE-mediumCall for participation: Experience needed to fix: Medium / intermediateCall for participation: Experience needed to fix: Medium / intermediateM-breaking-changeMeta: Implementing or merging this will introduce a breaking change.Meta: Implementing or merging this will introduce a breaking change.