clap: Error message for conflicted args outputs conflicting USAGE
Rust Version
rustc 1.34.1 (fc50f328b 2019-04-24)
Affected Version of clap
2.33.0
Bug or Feature Request Summary
There are 2 conflicting args: a
and b
. When both are issued, USAGE outputs the invalid command again.
Expected Behavior Summary
error: The argument '-b' cannot be used with '-a'
USAGE:
clap-fix -a
clap-fix -b
Actual Behavior Summary
error: The argument '-b' cannot be used with '-a'
USAGE:
clap-fix -a -b
Steps to Reproduce the issue
cargo run -- -a -b
Sample Code or Link to Sample Code
extern crate clap;
use clap::{Arg, App};
fn main() {
App::new("Conflict USAGE")
.arg(Arg::with_name("a")
.short("a")
.conflicts_with("b")
)
.arg(Arg::with_name("b")
.short("b")
.conflicts_with("a")
)
.get_matches();
}
Debug output
Debug Output
Running `target/debug/clap-fix -a -b`
DEBUG👏Parser::propagate_settings: self=Conflict USAGE, g_settings=AppFlags(
(empty)
)
DEBUG👏Parser::get_matches_with;
DEBUG👏Parser::create_help_and_version;
DEBUG👏Parser::create_help_and_version: Building --help
DEBUG👏Parser::create_help_and_version: Building --version
DEBUG👏Parser::get_matches_with: Begin parsing ‘“-a”’ ([45, 97])
DEBUG👏Parser::is_new_arg:“-a”:NotFound
DEBUG👏Parser::is_new_arg: arg_allows_tac=false
DEBUG👏Parser::is_new_arg: - found
DEBUG👏Parser::is_new_arg: starts_new_arg=true
DEBUG👏Parser::possible_subcommand: arg=“-a”
DEBUG👏Parser::get_matches_with: possible_sc=false, sc=None
DEBUG👏ArgMatcher::process_arg_overrides:None;
DEBUG👏Parser::parse_short_arg: full_arg=“-a”
DEBUG👏Parser::parse_short_arg:iter:a
DEBUG👏Parser::parse_short_arg:iter🅰️ Found valid flag
DEBUG👏Parser::check_for_help_and_version_char;
DEBUG👏Parser::check_for_help_and_version_char: Checking if -a is help or version…Neither
DEBUG👏Parser::parse_flag;
DEBUG👏ArgMatcher::inc_occurrence_of: arg=a
DEBUG👏ArgMatcher::inc_occurrence_of: first instance
DEBUG👏Parser::groups_for_arg: name=a
DEBUG👏Parser::groups_for_arg: No groups defined
DEBUG👏Parser:get_matches_with: After parse_short_arg Flag
DEBUG👏Parser::get_matches_with: Begin parsing ‘“-b”’ ([45, 98])
DEBUG👏Parser::is_new_arg:“-b”:Flag
DEBUG👏Parser::is_new_arg: arg_allows_tac=false
DEBUG👏Parser::is_new_arg: - found
DEBUG👏Parser::is_new_arg: starts_new_arg=true
DEBUG👏Parser::possible_subcommand: arg=“-b”
DEBUG👏Parser::get_matches_with: possible_sc=false, sc=None
DEBUG👏ArgMatcher::process_arg_overrides:Some(“a”);
DEBUG👏Parser::parse_short_arg: full_arg=“-b”
DEBUG👏Parser::parse_short_arg:iter:b
DEBUG👏Parser::parse_short_arg:iter🅱️ Found valid flag
DEBUG👏Parser::check_for_help_and_version_char;
DEBUG👏Parser::check_for_help_and_version_char: Checking if -b is help or version…Neither
DEBUG👏Parser::parse_flag;
DEBUG👏ArgMatcher::inc_occurrence_of: arg=b
DEBUG👏ArgMatcher::inc_occurrence_of: first instance
DEBUG👏Parser::groups_for_arg: name=b
DEBUG👏Parser::groups_for_arg: No groups defined
DEBUG👏Parser:get_matches_with: After parse_short_arg Flag
DEBUG👏ArgMatcher::process_arg_overrides:Some(“b”);
DEBUG👏Parser::remove_overrides:[];
DEBUG👏Validator::validate;
DEBUG👏Parser::add_defaults;
DEBUG👏Validator::validate_blacklist;
DEBUG👏Validator::validate_blacklist:iter:a;
DEBUG👏Parser::groups_for_arg: name=a
DEBUG👏Parser::groups_for_arg: No groups defined
DEBUG👏Validator::validate_blacklist:iter:b;
DEBUG👏Parser::groups_for_arg: name=b
DEBUG👏Parser::groups_for_arg: No groups defined
DEBUG👏Validator::validate_blacklist:iter🅱️ Checking blacklisted arg
DEBUG👏Validator::validate_blacklist:iter🅱️ matcher contains it…
DEBUG👏build_err!: name=b
DEBUG👏build_err!: ‘Some(“-a”)’ conflicts with ‘b’
DEBUG👏usage::create_usage_with_title;
DEBUG👏usage::create_usage_no_title;
DEBUG👏usage::smart_usage;
DEBUG👏usage::get_required_usage_from: reqs=[“a”, “b”], extra=None
DEBUG👏usage::get_required_usage_from: after init desc_reqs=[]
DEBUG👏usage::get_required_usage_from: no more children
DEBUG👏usage::get_required_usage_from: final desc_reqs=[“a”, “b”]
DEBUG👏usage::get_required_usage_from: args_in_groups=[]
DEBUG👏usage::get_required_usage_from:iter🅰️
DEBUG👏usage::get_required_usage_from:iter🅱️
DEBUG👏build_err!: It was a flag…
DEBUG👏Parser::color;
DEBUG👏Parser::color: Color setting…Auto
DEBUG👏is_a_tty: stderr=true
DEBUG👏Colorizer::error;
DEBUG👏Colorizer::warning;
DEBUG👏Colorizer::warning;
DEBUG👏Colorizer::good;
error: The argument ‘-b’ cannot be used with ‘-a’
USAGE:
clap-fix -a -b
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (11 by maintainers)
This issue now has bounty of $10. More info here
No, we didn’t. And it also haven’t been working anyway, the test was not asserted. I think it’s simply not implemented.
@captain-yossarian will going to have to trace where the erroneous message originates from and implement the right message.
Hey Captain! Feel free to ask for guidance!
There was a joke about a captain who doesn’t guide but needs guidance instead here, but it was pretty gross and the censorship deleted it.Put
assert!
in front of this https://github.com/clap-rs/clap/blob/master/tests/conflicts.rs#L101 and https://github.com/clap-rs/clap/blob/master/tests/conflicts.rs#L111, and you should have tests that will fail.@jojva @CreepySkeleton Hi, can take this up?