1 //! How to use `#[structopt(skip)]`
2
3 use structopt::StructOpt;
4
5 #[derive(StructOpt, Debug, PartialEq)]
6 pub 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)]
23 enum Kind {
24 A,
25 B,
26 }
27
28 impl Default for Kind {
default() -> Self29 fn default() -> Self {
30 return Kind::B;
31 }
32 }
33
main()34 fn 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 }
48