mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
631e54bc71
Inspired by part of the conversation at #3234
29 lines
1.1 KiB
Rust
29 lines
1.1 KiB
Rust
fn main() {
|
|
let cmd = clap::Command::new("cargo")
|
|
.bin_name("cargo")
|
|
.styles(CLAP_STYLING)
|
|
.subcommand_required(true)
|
|
.subcommand(
|
|
clap::command!("example").arg(
|
|
clap::arg!(--"manifest-path" <PATH>)
|
|
.value_parser(clap::value_parser!(std::path::PathBuf)),
|
|
),
|
|
);
|
|
let matches = cmd.get_matches();
|
|
let matches = match matches.subcommand() {
|
|
Some(("example", matches)) => matches,
|
|
_ => unreachable!("clap should ensure we don't get here"),
|
|
};
|
|
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);
|