-
Notifications
You must be signed in to change notification settings - Fork 150
Description
In the same vein as convenience features like #134 and #18, add support for the automatic use of Default, if implemented. This would be a breaking change if done poorly, and in any case I'm not sure if the procedural macro system is powerful enough to "detect" trait implementations. I'd therefore propose the following syntax, inspired by #18:
#[derive(Debug)]
struct Value(String);
impl Default for Value {
fn default() -> Value {
Value("default".to_string())
}
}
impl FromStr for Value { ... }
#[derive(Debug, StructOpt)]
struct Opt {
// using the proposed automatic name syntax
#[structopt(long, short, default)]
value: Value
}Basically, if the default key is present, then use the Default trait if the flag isn't given. I'd also be okay with default_value being the key, but my suggestion is that it be slightly different because under the hood, something slightly different is happening. This isn't using clap's default_value builder method, since it requires a str. Rather, structopt itself will handle the logic for filling in the default value if necessary.
This could have implications for #123, as well.