-
-
Notifications
You must be signed in to change notification settings - Fork 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
Bring back possible_values
(because ValueEnum
does not fit everything)
#4504
Comments
You can also do |
@epage I apologize, the fault lies with me for not reading the documentation carefully. I searched for the term "possible" on the docs.rs page for clap and find only the |
It doesn't seem to be possible to pass a runtime slice or |
This dynamically generated list of possible values. Inspired by clap-rs#4504
This dynamically generated list of possible values. Inspired by clap-rs#4504
Please complete the following tasks
Clap Version
4.0.26
Describe your use case
There are cases where I want to only limit user choices between strings. The behavior of the program remain exactly the same (i.e. no branches related to the user choice). For example: Choosing a weekday only to be printed out, choosing a profile between "release" and "debug" only to infer the binary path, etc.
In such cases, an enum (that derives
ValueEnum
) would be inconvenient since it requires me to writematch
to convert every single enum variant to corresponding strings.Describe the solution you'd like
Bring back
possible_values
or something similar.Alternatives, if applicable
Derive strum on the value enum. However, this method is not optimal as the resulting program still parse a string into a value enum only to convert it back to the original string.
Use
value_parser = [PossibleValue::new("..."), ...]
but this is unwieldy and cumbersome, especially when written in derive code.Additional Context
I exclusively use
#[derive(clap::Parser)]
. I've never use the args builder directly.The text was updated successfully, but these errors were encountered: