diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/enum_in_args_with_strum.rs | 27 | ||||
-rw-r--r-- | examples/example.rs | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/examples/enum_in_args_with_strum.rs b/examples/enum_in_args_with_strum.rs new file mode 100644 index 0000000..a045a48 --- /dev/null +++ b/examples/enum_in_args_with_strum.rs @@ -0,0 +1,27 @@ +use structopt::StructOpt; +use strum::{EnumString, EnumVariantNames, VariantNames}; + +const DEFAULT: &str = "txt"; + +#[derive(StructOpt, Debug)] +struct Opt { + #[structopt( + long, + possible_values = Format::VARIANTS, + case_insensitive = true, + default_value = DEFAULT, + )] + format: Format, +} + +#[derive(EnumString, EnumVariantNames, Debug)] +#[strum(serialize_all = "kebab_case")] +enum Format { + Txt, + Md, + Html, +} + +fn main() { + println!("{:?}", Opt::from_args()); +} diff --git a/examples/example.rs b/examples/example.rs index 7a9a514..71cc124 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -37,7 +37,7 @@ struct Opt { // An optional list of values, will be `None` if not present on // the command line, will be `Some(vec![])` if no argument is - // provided (i.e. `--optv`) and will be `Some(Some(String))` if + // provided (i.e. `--optv`) and will be `Some(Vec<String>)` if // argument list is provided (e.g. `--optv a b c`). #[structopt(long)] optv: Option<Vec<String>>, |