1 // Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8
9 use structopt::StructOpt;
10
11 #[derive(StructOpt, Debug)]
12 #[structopt(name = "make-cookie")]
13 struct MakeCookie {
14 #[structopt(short)]
15 s: String,
16
17 #[structopt(skip, flatten)]
18 cmd: Command,
19 }
20
21 #[derive(StructOpt, Debug)]
22 enum Command {
23 #[structopt(name = "pound")]
24 /// Pound acorns into flour for cookie dough.
25 Pound { acorns: u32 },
26
27 Sparkle {
28 #[structopt(short)]
29 color: String,
30 },
31 }
32
33 impl Default for Command {
default() -> Self34 fn default() -> Self {
35 Command::Pound { acorns: 0 }
36 }
37 }
38
main()39 fn main() {
40 let opt = MakeCookie::from_args();
41 println!("{:?}", opt);
42 }
43