Skip to content

clap 4.0 equivalent of possible_values with strumVARIANTS? #4264

Answered by epage
repi asked this question in Q&A
Discussion options

You must be logged in to vote

And while that builds, if one doesn't specify such an argument when parsing a command-line it panics on this instead of using the default type:

All the value parser knows is possible string values; you also need to set the appropriate type for it.

    #[arg(long, default_value_t, ignore_case = true, value_parser = clap::builder::PossibleValuesParser::new(OutputFormat::VARIANTS).map(|s| s.parse::<OutputFormat>().unwrap())]
    pub output_format: OutputFormat,

See also #3855

On a related minor note, is there a way to enable case insensitive argument matching by default instead of specifying it on every argument?

Not at the moment. That is an interesting thought though, if someone wants …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by repi
Comment options

You must be logged in to vote
3 replies
@epage
Comment options

@repi
Comment options

@devklick
Comment options

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