clap/examples/cargo-example.rs

30 lines
1.1 KiB
Rust
Raw Normal View History

fn main() {
2022-02-14 21:47:20 +00:00
let cmd = clap::Command::new("cargo")
.bin_name("cargo")
.styles(CLAP_STYLING)
.subcommand_required(true)
.subcommand(
2022-02-15 14:33:38 +00:00
clap::command!("example").arg(
clap::arg!(--"manifest-path" <PATH>)
2022-05-23 15:50:11 +00:00
.value_parser(clap::value_parser!(std::path::PathBuf)),
),
);
2022-02-14 21:47:20 +00:00
let matches = cmd.get_matches();
let matches = match matches.subcommand() {
Some(("example", matches)) => matches,
_ => unreachable!("clap should ensure we don't get here"),
};
2022-05-23 15:50:11 +00:00
let manifest_path = matches.get_one::<std::path::PathBuf>("manifest-path");
println!("{manifest_path:?}");
}
// See also `clap_cargo::style::CLAP_STYLING`
pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
.header(clap_cargo::style::HEADER)
.usage(clap_cargo::style::USAGE)
.literal(clap_cargo::style::LITERAL)
.placeholder(clap_cargo::style::PLACEHOLDER)
.error(clap_cargo::style::ERROR)
.valid(clap_cargo::style::VALID)
.invalid(clap_cargo::style::INVALID);