aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-08-09 10:44:46 -0700
committerJoel Galenson <jgalenson@google.com>2021-08-09 10:44:46 -0700
commit108a00fc514b13e7a79994fa61a90f0f2b265a39 (patch)
tree09fa4d8ab7933bd6aea36bbcd7389cd71e2a373a /examples
parentd1bb8b6b842acc449b9ea2a7ef6d71c21ce105a0 (diff)
downloadstructopt-108a00fc514b13e7a79994fa61a90f0f2b265a39.tar.gz
Upgrade rust/crates/structopt to 0.3.22
Test: make Change-Id: Id5e1a89dea1beece1f6ec549d6afc4dac67dc9b4
Diffstat (limited to 'examples')
-rw-r--r--examples/enum_in_args_with_strum.rs27
-rw-r--r--examples/example.rs2
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>>,