cargo_example_derive/cargo-example-derive.rs
1use clap::Parser;
2
3#[derive(Parser)] // requires `derive` feature
4#[command(name = "cargo")]
5#[command(bin_name = "cargo")]
6#[command(styles = CLAP_STYLING)]
7enum CargoCli {
8 ExampleDerive(ExampleDeriveArgs),
9}
10
11// See also `clap_cargo::style::CLAP_STYLING`
12pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
13 .header(clap_cargo::style::HEADER)
14 .usage(clap_cargo::style::USAGE)
15 .literal(clap_cargo::style::LITERAL)
16 .placeholder(clap_cargo::style::PLACEHOLDER)
17 .error(clap_cargo::style::ERROR)
18 .valid(clap_cargo::style::VALID)
19 .invalid(clap_cargo::style::INVALID);
20
21#[derive(clap::Args)]
22#[command(version, about, long_about = None)]
23struct ExampleDeriveArgs {
24 #[arg(long)]
25 manifest_path: Option<std::path::PathBuf>,
26}
27
28fn main() {
29 let CargoCli::ExampleDerive(args) = CargoCli::parse();
30 println!("{:?}", args.manifest_path);
31}