1 use std::process::exit;
2
3 use clap::{App, AppSettings, Arg};
4
applet_commands() -> [App<'static>; 2]5 fn applet_commands() -> [App<'static>; 2] {
6 [
7 App::new("true").about("does nothing successfully"),
8 App::new("false").about("does nothing unsuccessfully"),
9 ]
10 }
11
main()12 fn main() {
13 let app = App::new(env!("CARGO_CRATE_NAME"))
14 .setting(AppSettings::Multicall)
15 .subcommand(
16 App::new("busybox")
17 .setting(AppSettings::ArgRequiredElseHelp)
18 .subcommand_value_name("APPLET")
19 .subcommand_help_heading("APPLETS")
20 .arg(
21 Arg::new("install")
22 .long("install")
23 .help("Install hardlinks for all subcommands in path")
24 .exclusive(true)
25 .takes_value(true)
26 .default_missing_value("/usr/local/bin")
27 .use_delimiter(false),
28 )
29 .subcommands(applet_commands()),
30 )
31 .subcommands(applet_commands());
32
33 let matches = app.get_matches();
34 let mut subcommand = matches.subcommand();
35 if let Some(("busybox", cmd)) = subcommand {
36 if cmd.occurrences_of("install") > 0 {
37 unimplemented!("Make hardlinks to the executable here");
38 }
39 subcommand = cmd.subcommand();
40 }
41 match subcommand {
42 Some(("false", _)) => exit(1),
43 Some(("true", _)) => exit(0),
44 _ => unreachable!("parser should ensure only valid subcommand names are used"),
45 }
46 }
47