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