blob: 1f44769fc1d28a74f7ef5ab0bc6239d1489c2c74 [file] [log] [blame]
Matthew Maurer32e76692020-06-02 11:15:15 -07001//! How to use `#[structopt(skip)]`
2
3use structopt::StructOpt;
4
5#[derive(StructOpt, Debug, PartialEq)]
6pub struct Opt {
7 #[structopt(long, short)]
8 number: u32,
9 #[structopt(skip)]
10 k: Kind,
11 #[structopt(skip)]
12 v: Vec<u32>,
13
14 #[structopt(skip = Kind::A)]
15 k2: Kind,
16 #[structopt(skip = vec![1, 2, 3])]
17 v2: Vec<u32>,
18 #[structopt(skip = "cake")] // &str implements Into<String>
19 s: String,
20}
21
22#[derive(Debug, PartialEq)]
23enum Kind {
24 A,
25 B,
26}
27
28impl Default for Kind {
29 fn default() -> Self {
30 return Kind::B;
31 }
32}
33
34fn main() {
35 assert_eq!(
36 Opt::from_iter(&["test", "-n", "10"]),
37 Opt {
38 number: 10,
39 k: Kind::B,
40 v: vec![],
41
42 k2: Kind::A,
43 v2: vec![1, 2, 3],
44 s: String::from("cake")
45 }
46 );
47}