-
Please complete the following tasks
Rust Versionrustc 1.50.0 (cb75ad5db 2021-02-10) Clap Version2.33.3 Minimal reproducible code// src/main.rs
use clap::{App, Arg};
fn build_cli() -> App<'static, 'static> {
App::new("example").args(&[Arg::with_name("foo"), Arg::with_name("bar")])
}
fn main() {
let m = build_cli().get_matches();
if m.is_present("foo") {
println!("foo");
}
if m.is_present("bar") {
println!("bar");
}
} Steps to reproduce the bug with the above code
Actual Behaviourit returns "foo" Expected Behaviourshouldn't it return "bar"? Additional ContextNo response Debug Output
I hope I didn't understand something wrong in the documentation or missed another issue referencing this. |
Beta Was this translation helpful? Give feedback.
Answered by
ldm0
Mar 9, 2021
Replies: 1 comment
-
This is not a bug. The argument you defined is called positional arguments, which takes a value. I guess you want flags, you can try |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
theguy147
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not a bug. The argument you defined is called positional arguments, which takes a value. I guess you want flags, you can try
Arg::with_name("foo").long("foo"), Arg::with_name("bar").long("bar")
and then usecargo run -- --bar