Open
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
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 and skip
like so:
#[derive(Debug, Parser)]
struct Args {
#[clap(value_parser = enum_parser)]
arg: Enum,
}
#[derive(ValueEnum, Clone, Debug)]
enum Enum {
A,
B,
#[clap(skip)]
Other(String),
}
fn enum_parser(value: &str) -> Result<Enum, Infallible> {
Ok(Enum::from_str(value, true).unwrap_or_else(|_| Enum::Other(value.to_owned())))
}
Additional Context
No response