Skip to content

Optional value of argument #383

Answered by pacak
UltraMachine asked this question in Q&A
Aug 1, 2024 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Same idea, splitting it into primitive parsers. None when not present and Some otherwise means .optional() goes at the end, and inner parsers produce value without Option, so --bar should make "default" and --bar=value should make "value". You achieve former with req_flag and later with argument.

    let bar_flag = long("bar").req_flag("default".into());
    let bar_arg = long("bar").argument::<String>("BAR");
    let bar = construct!([bar_arg, bar_flag]);
    bar.optional()

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@UltraMachine
Comment options

@pacak
Comment options

@UltraMachine
Comment options

@pacak
Comment options

Answer selected by UltraMachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants