aboutsummaryrefslogtreecommitdiff
path: root/structopt/examples/skip.rs
blob: 1f44769fc1d28a74f7ef5ab0bc6239d1489c2c74 (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
43
44
45
46
47
//! How to use `#[structopt(skip)]`

use structopt::StructOpt;

#[derive(StructOpt, Debug, PartialEq)]
pub struct Opt {
    #[structopt(long, short)]
    number: u32,
    #[structopt(skip)]
    k: Kind,
    #[structopt(skip)]
    v: Vec<u32>,

    #[structopt(skip = Kind::A)]
    k2: Kind,
    #[structopt(skip = vec![1, 2, 3])]
    v2: Vec<u32>,
    #[structopt(skip = "cake")] // &str implements Into<String>
    s: String,
}

#[derive(Debug, PartialEq)]
enum Kind {
    A,
    B,
}

impl Default for Kind {
    fn default() -> Self {
        return Kind::B;
    }
}

fn main() {
    assert_eq!(
        Opt::from_iter(&["test", "-n", "10"]),
        Opt {
            number: 10,
            k: Kind::B,
            v: vec![],

            k2: Kind::A,
            v2: vec![1, 2, 3],
            s: String::from("cake")
        }
    );
}