01_quick_derive/
01_quick.rs1use std::path::PathBuf;
2
3use clap::{Parser, Subcommand};
4
5#[derive(Parser)]
6#[command(version, about, long_about = None)]
7struct Cli {
8 name: Option<String>,
10
11 #[arg(short, long, value_name = "FILE")]
13 config: Option<PathBuf>,
14
15 #[arg(short, long, action = clap::ArgAction::Count)]
17 debug: u8,
18
19 #[command(subcommand)]
20 command: Option<Commands>,
21}
22
23#[derive(Subcommand)]
24enum Commands {
25 Test {
27 #[arg(short, long)]
29 list: bool,
30 },
31}
32
33fn main() {
34 let cli = Cli::parse();
35
36 if let Some(name) = cli.name.as_deref() {
38 println!("Value for name: {name}");
39 }
40
41 if let Some(config_path) = cli.config.as_deref() {
42 println!("Value for config: {}", config_path.display());
43 }
44
45 match cli.debug {
48 0 => println!("Debug mode is off"),
49 1 => println!("Debug mode is kind of on"),
50 2 => println!("Debug mode is on"),
51 _ => println!("Don't be crazy"),
52 }
53
54 match &cli.command {
57 Some(Commands::Test { list }) => {
58 if *list {
59 println!("Printing testing lists...");
60 } else {
61 println!("Not printing testing lists...");
62 }
63 }
64 None => {}
65 }
66
67 }