-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback for ValueEnum #5885
Comments
I tried to implement a solution, but it turns out this is not a purely proc-macro change. This would require to either add fallback to the |
Not sure what your preferred implementation would be here, should you want to implement this. |
Serde calls such an attribute [ Adding to An important question for this is also how to handle different types. One option is to only accept We'd also need to look at the impact on dynamic completions in case it affects the design at all. |
I'd have gone for only String based types for now, though I could see someone wanting to use, e.g., a number. Though then you might want to have multiple Currently, Adding a new function with a default implementation to For dynamic completions I'd have said it should be considered To support completions for the |
I don't remember the details but it looks like |
Yeah, clap/clap_builder/src/builder/value_parser.rs Lines 1119 to 1126 in f89134d
let value = E::from_str(value, ignore_case).map_err(|| { The other would be to move the generating of a proper error inside |
Please complete the following tasks
Clap Version
4.5.26
Describe your use case
I'd like to have support for a fallback option when using
ValueEnum
.Describe the solution you'd like
When
derive(ValueEnum)
is used I'd like to have a variant e.g.,Other(String)
, annotated with something like#[clap(other|fallback)]
to contain the literal value if none of the enum variants matches.Alternatives, if applicable
Using
value_parser
to andskip
like so:Additional Context
No response
The text was updated successfully, but these errors were encountered: