argh
argh copied to clipboard
Use the Default trait for enums used as options
It should be possible to use an enum as the possible value of an option, without wrapping it in an Option when and if the enum implements Default.
Current example :
#[derive(argh::FromArgs)]
struct Args {
/// output format
#[argh(option)]
format: Option<OutputFormat>,
}
let args: Args = argh::from_env();
let format = args.format.unwrap_or_default();
Using the Default trait :
#[derive(argh::FromArgs)]
struct Args {
/// output format
#[argh(option)]
format: OutputFormat, // enum should implement Default
}
I would definitely accept a PR for this, I've thought this in the past as well
I've yet to learn how to write derive macros. I have time these days, maybe I'll give it shot.