-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
A-deriveArea: #[derive]` macro APIArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsS-blockedStatus: Blocked on something else such as an RFC or other implementation work.Status: Blocked on something else such as an RFC or other implementation work.
Description
Please complete the following tasks
- I have searched the discussions
- I have searched the open and rejected issues
Clap Version
4.5.54
Describe your use case
I don’t like that I have to repeat myself here:
#[derive(Debug, Parser)]
struct Args {
#[arg(long, num_args = ..=1, require_equals = true, default_missing_value = "the-default")]
some_opt: Option<ThingImplementingDefault>,
}
#[derive(Debug, Default, Clone, clap::ValueEnum)]
enum ThingImplementingDefault {
#[default]
TheDefault,
SomethingElse,
}Describe the solution you'd like
Would be great if Optional<ThingImplementingDefault> could be made to behave like this without repetition:
- nothing ->
None --some-opt->Some(Default::default())--some-opt=something-else->Some(value.parse()?)
Maybe just default_missing_value without argument would behave like this?
Alternatives, if applicable
Implement default_missing_value_t, then I could do default_missing_value_t = Some(Default::default())
Additional Context
See also #6109 for more default_missing_value utility
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-deriveArea: #[derive]` macro APIArea: #[derive]` macro APIC-enhancementCategory: Raise on the bar on expectationsCategory: Raise on the bar on expectationsS-blockedStatus: Blocked on something else such as an RFC or other implementation work.Status: Blocked on something else such as an RFC or other implementation work.