aboutsummaryrefslogtreecommitdiff
path: root/examples/enum_in_args_with_strum.rs
blob: 7893e78eaeeb54512e5919b9c7d8e2a668cef519 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Running this example with --help prints this message:
//! -----------------------------------------------------
//! structopt 0.3.25
//! 
//! USAGE:
//!     enum_in_args_with_strum [OPTIONS]
//! 
//! FLAGS:
//!     -h, --help       Prints help information
//!     -V, --version    Prints version information
//! 
//! OPTIONS:
//!         --format <format>     [default: txt]  [possible values: txt, md, html]
//! -----------------------------------------------------

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());
}