Repository navigation
Please complete the following tasks
Clap Version2.33 Describe your use caseI would like to have a special option that I can designate that the flag passed on the command line is the actual value also. Describe the solution you'd likeThe feature I am asking for is effectively how the compression level flag in The way I could envision this working would be to have a special symbol let m = App::new("gzip")
.arg(Arg::with_name("#"))
.get_matches_from(vec![
"gzip", "-3"
]);
assert!(m.is_present("#"));
assert_eq!(m.value_of("#"), Some(3));Alternatives, if applicableNo response Additional ContextNo response |
Replies: 7 comments 2 replies
|
Hey, this is definitely possible on 3.0.0-beta.4 and should be possible on 2.33 too. Not sure what gave you the impression that it is not. Please read the documentation and try it out and open a bug report if it's not working. |
|
I did read the documentation, but obviously I missed the relevant option for doing this. Are you able to point me in the right direction? |
|
What's the value you are getting for |
|
When I try and build this I get |
|
Use https://docs.rs/clap/2.33.3/clap/struct.Arg.html#method.allow_hyphen_values for that arg. |
|
I'm still getting the same error. use clap::{Arg, App};
fn main() {
let m = App::new("gzip")
.arg(Arg::with_name("#").allow_hyphen_values(true))
.get_matches_from(vec!["gzip", "-3"]);
assert!(m.is_present("#"));
assert_eq!(m.value_of("#"), Some("3"));
} |
|
On v2 it seems to be a bug with using fn main() {
let m = App::new("gzip")
.setting(AppSettings::AllowLeadingHyphen)
.arg(Arg::with_name("#").allow_hyphen_values(true))
.get_matches_from(vec!["gzip", "-3"]);
assert!(m.is_present("#"));
assert_eq!(m.value_of("#"), Some("-3"));
}Note the value includes the |
On v2 it seems to be a bug with using
Arg::hyphen_valueson free/positional arguments. This bug requires you to also useAppSettings::AllowLeadingHyphen:Note the value includes the
-character which you'll have to strip for your pruposes.