Skip to content

Commit

Permalink
Add an example using strum
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXitoi committed Mar 5, 2021
1 parent 3848d5b commit 8161b15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ paw_dep = { version = "1", optional = true, package = "paw" }
[dev-dependencies]
trybuild = { version = "1.0.5", features = ["diff"] }
rustversion = "1"
strum = { version = "0.20", features = ["derive"] }
27 changes: 27 additions & 0 deletions examples/enum_in_args_with_strum.rs
Original file line number Diff line number Diff line change
@@ -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());
}

0 comments on commit 8161b15

Please sign in to comment.