mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
7e899cd340
This reverts commits 24cb8b1..d0abb37 from clap-rs/clap#1840 This is part of #16. clap-rs/clap#1840 wasn't the right call but we don't have time to make the decision now, so instead of having one option and changing it in 4.0, this reverts back to clap2 behavior.
41 lines
1.5 KiB
Rust
41 lines
1.5 KiB
Rust
//! Example of a `busybox-style` multicall program
|
|
//!
|
|
//! See the documentation for clap::AppSettings::Multicall for rationale.
|
|
//!
|
|
//! This example omits every command except true and false,
|
|
//! which are the most trivial to implement,
|
|
//! but includes the `--install` option as an example of why it can be useful
|
|
//! for the main program to take arguments that aren't applet subcommands.
|
|
|
|
use std::process::exit;
|
|
|
|
use clap::{App, AppSettings, Arg};
|
|
|
|
fn main() {
|
|
let app = App::new(env!("CARGO_CRATE_NAME"))
|
|
.setting(AppSettings::ArgRequiredElseHelp)
|
|
.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),
|
|
)
|
|
.subcommand(App::new("true").about("does nothing successfully"))
|
|
.subcommand(App::new("false").about("does nothing unsuccessfully"));
|
|
|
|
#[cfg(feature = "unstable-multicall")]
|
|
let app = app.setting(AppSettings::Multicall);
|
|
let matches = app.get_matches();
|
|
if matches.occurrences_of("install") > 0 {
|
|
unimplemented!("Make hardlinks to the executable here");
|
|
}
|
|
|
|
match matches.subcommand_name() {
|
|
Some("true") => exit(0),
|
|
Some("false") => exit(1),
|
|
_ => unreachable!("parser should ensure only valid subcommand names are used"),
|
|
}
|
|
}
|