]> git.proxmox.com Git - cargo.git/blob - vendor/clap/examples/tutorial_derive/03_04_subcommands_alt.rs
0a5b60682d42466be917cb9720b4611903062ffe
[cargo.git] / vendor / clap / examples / tutorial_derive / 03_04_subcommands_alt.rs
1 use clap::{Args, Parser, Subcommand};
2
3 #[derive(Parser)]
4 #[clap(author, version, about, long_about = None)]
5 #[clap(propagate_version = true)]
6 struct Cli {
7 #[clap(subcommand)]
8 command: Commands,
9 }
10
11 #[derive(Subcommand)]
12 enum Commands {
13 /// Adds files to myapp
14 Add(Add),
15 }
16
17 #[derive(Args)]
18 struct Add {
19 name: Option<String>,
20 }
21
22 fn main() {
23 let cli = Cli::parse();
24
25 // You can check for the existence of subcommands, and if found use their
26 // matches just as you would the top level cmd
27 match &cli.command {
28 Commands::Add(name) => {
29 println!("'myapp add' was used, name is: {:?}", name.name)
30 }
31 }
32 }