• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 clap::Parser;
10 
11 #[derive(Parser, Debug)]
12 #[command(name = "make-cookie")]
13 struct MakeCookie {
14     #[arg(short)]
15     s: String,
16 
17     #[command(skip, flatten)]
18     cmd: Command,
19 }
20 
21 #[derive(Parser, Debug)]
22 enum Command {
23     #[command(name = "pound")]
24     /// Pound acorns into flour for cookie dough.
25     Pound { acorns: u32 },
26 
27     Sparkle {
28         #[arg(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::parse();
41     println!("{:?}", opt);
42 }
43