-
-
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
Arguments with takes_value(false) still accept "compact"-style arguments #1543
Comments
Can we reopen this issue? I tested this from the tip of the git tree and the problem is still happening, also I faced the same issue on my own code using Modify #[cfg(feature = "env")]
#[test]
fn multiple_occurrences_of_before_env() {
let cmd = Command::new("mo_before_env").arg(
Arg::new("verbose")
.env("VERBOSE")
.short('v')
.long("verbose")
.takes_value(false)
.multiple_occurrences(true),
);
let m = cmd.clone().try_get_matches_from(vec![""]);
assert!(m.is_ok(), "{}", m.unwrap_err());
assert_eq!(m.unwrap().occurrences_of("verbose"), 0);
let m = cmd.clone().try_get_matches_from(vec!["", "-v"]);
assert!(m.is_ok(), "{}", m.unwrap_err());
assert_eq!(m.unwrap().occurrences_of("verbose"), 1);
let m = cmd.clone().try_get_matches_from(vec!["", "-vv"]);
assert!(m.is_ok(), "{}", m.unwrap_err());
assert_eq!(m.unwrap().occurrences_of("verbose"), 2);
let m = cmd.clone().try_get_matches_from(vec!["", "-vvv"]);
assert!(m.is_ok(), "{}", m.unwrap_err());
assert_eq!(m.unwrap().occurrences_of("verbose"), 3);
// this chunk of code is added to test
// notice `-vvv=false`, test result is fine, no error out
let m = cmd.clone().try_get_matches_from(vec!["", "-vvv=false"]);
assert!(m.is_ok(), "{}", m.unwrap_err());
assert_eq!(m.unwrap().occurrences_of("verbose"), 3);
} as well I didn't see relevant changes that fix this issue in #2619. |
I just tried reproducing with the code sample you gave and it failed
|
Rust Version
Affected Version of clap
Bug or Feature Request Summary
Arguments configured to not take a value still successfully parse from the
--key=value
form.Expected Behavior Summary
The command line should fail to validate (or only accept
--key=true
or--key=false
.Actual Behavior Summary
The command line successfully validates as if it just contained
--key
.Sample Code or Link to Sample Code
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d08679674fa982b892dcc26d8ed8bb25
The text was updated successfully, but these errors were encountered: