• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Running this example with --help prints this message:
2 //! -----------------------------------------------------
3 //! structopt 0.3.25
4 //!
5 //! USAGE:
6 //!     enum_in_args_with_strum [OPTIONS]
7 //!
8 //! FLAGS:
9 //!     -h, --help       Prints help information
10 //!     -V, --version    Prints version information
11 //!
12 //! OPTIONS:
13 //!         --format <format>     [default: txt]  [possible values: txt, md, html]
14 //! -----------------------------------------------------
15 
16 use structopt::StructOpt;
17 use strum::{EnumString, EnumVariantNames, VariantNames};
18 
19 const DEFAULT: &str = "txt";
20 
21 #[derive(StructOpt, Debug)]
22 struct Opt {
23     #[structopt(
24         long,
25         possible_values = Format::VARIANTS,
26         case_insensitive = true,
27         default_value = DEFAULT,
28     )]
29     format: Format,
30 }
31 
32 #[derive(EnumString, EnumVariantNames, Debug)]
33 #[strum(serialize_all = "kebab_case")]
34 enum Format {
35     Txt,
36     Md,
37     Html,
38 }
39 
main()40 fn main() {
41     println!("{:?}", Opt::from_args());
42 }
43