From 108a00fc514b13e7a79994fa61a90f0f2b265a39 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 9 Aug 2021 10:44:46 -0700 Subject: Upgrade rust/crates/structopt to 0.3.22 Test: make Change-Id: Id5e1a89dea1beece1f6ec549d6afc4dac67dc9b4 --- examples/enum_in_args_with_strum.rs | 27 +++++++++++++++++++++++++++ examples/example.rs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 examples/enum_in_args_with_strum.rs (limited to 'examples') 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)` if // argument list is provided (e.g. `--optv a b c`). #[structopt(long)] optv: Option>, -- cgit v1.2.3