clap
clap copied to clipboard
`serde`-like default value behavior
Maintainer's notes
- We can use the field's
Default::default
with#[clap(default_value_t)]
- Design work is needed for using the container's
Default::default
Issue by epage
Thursday May 03, 2018 at 13:17 GMT
Originally opened as https://github.com/TeXitoi/structopt/issues/105
It'd be nice to have annotations like serde for default values
- Use the struct's Default impl
- Use the field's Default impl
Comment by TeXitoi
Thursday May 03, 2018 at 13:38 GMT
The problem is that, most of the time, clap will not be able to show the default value (because just a few types implement Display).
default_value_t
allows you to do the type's Default
impl or a custom value of the type, so long as the type implements Display
.
I missed the case of using the container's Default::default
. The question is how to specify this. Serde does this by having a container-level default
attribute but for us to do that, we would make all fields optional. This would require a weird handling of structs to use flatten
to leverage it or a new way to specify it at the field level