Skip to content

clap 3.2: How to get equivalent of possible_values with conversion to field type? #3855

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

You must be logged in to vote

Yes, PossibleValuesParser only provides a String output type at this time.

In another thread, I gave this reply

The new design presupposes the field type when using possible values is a String. In the short term, you would need to write your own TypedValueParser and do #[clap(value_parser = LevelFilterValueParser)]. See PossibleValuesParser for inspiration. I'd also say feel free to open an issue requesting native support for this. I held off on natively supporting this because I was unsure how much it would be needed and what the combination of needs would be (would FromStr be sufficient or would it need to compose with another TypedValueParser, etc).

I would say in your case, you coul…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@kpreid
Comment options

Answer selected by kpreid
Comment options

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

@sunshowers
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