mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
03cb509d6c
This is to make room for a reasonable looking cargo plugin example. I got lazy and didn't update the tutorials.
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
use std::process::exit;
|
|
|
|
use clap::{App, AppSettings, Arg};
|
|
|
|
fn applet_commands() -> [App<'static>; 2] {
|
|
[
|
|
App::new("true").about("does nothing successfully"),
|
|
App::new("false").about("does nothing unsuccessfully"),
|
|
]
|
|
}
|
|
|
|
fn main() {
|
|
let app = App::new(env!("CARGO_CRATE_NAME"))
|
|
.setting(AppSettings::Multicall)
|
|
.subcommand(
|
|
App::new("busybox")
|
|
.setting(AppSettings::ArgRequiredElseHelp)
|
|
.subcommand_value_name("APPLET")
|
|
.subcommand_help_heading("APPLETS")
|
|
.arg(
|
|
Arg::new("install")
|
|
.long("install")
|
|
.help("Install hardlinks for all subcommands in path")
|
|
.exclusive(true)
|
|
.takes_value(true)
|
|
.default_missing_value("/usr/local/bin")
|
|
.use_delimiter(false),
|
|
)
|
|
.subcommands(applet_commands()),
|
|
)
|
|
.subcommands(applet_commands());
|
|
|
|
let matches = app.get_matches();
|
|
let mut subcommand = matches.subcommand();
|
|
if let Some(("busybox", cmd)) = subcommand {
|
|
if cmd.occurrences_of("install") > 0 {
|
|
unimplemented!("Make hardlinks to the executable here");
|
|
}
|
|
subcommand = cmd.subcommand();
|
|
}
|
|
match subcommand {
|
|
Some(("false", _)) => exit(1),
|
|
Some(("true", _)) => exit(0),
|
|
_ => unreachable!("parser should ensure only valid subcommand names are used"),
|
|
}
|
|
}
|