Skip to content
Discussion options

You must be logged in to vote

On v2 it seems to be a bug with using Arg::hyphen_values on free/positional arguments. This bug requires you to also use AppSettings::AllowLeadingHyphen:

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 - character which you'll have to strip for your pruposes.

Replies: 7 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@pksunkara
Comment options

@mbhall88
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by pksunkara
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2725 on September 23, 2021 12:43.