1 | use std::path::PathBuf; |
2 | use std::process::exit; |
3 | |
4 | use clap::{value_parser, Arg, ArgAction, Command}; |
5 | |
6 | fn applet_commands() -> [Command; 2] { |
7 | [ |
8 | Command::new("true" ).about("does nothing successfully" ), |
9 | Command::new("false" ).about("does nothing unsuccessfully" ), |
10 | ] |
11 | } |
12 | |
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 | .action(ArgAction::Set) |
27 | .default_missing_value("/usr/local/bin" ) |
28 | .value_parser(value_parser!(PathBuf)), |
29 | ) |
30 | .subcommands(applet_commands()), |
31 | ) |
32 | .subcommands(applet_commands()); |
33 | |
34 | let matches = cmd.get_matches(); |
35 | let mut subcommand = matches.subcommand(); |
36 | if let Some(("busybox" , cmd)) = subcommand { |
37 | if cmd.contains_id("install" ) { |
38 | unimplemented!("Make hardlinks to the executable here" ); |
39 | } |
40 | subcommand = cmd.subcommand(); |
41 | } |
42 | match subcommand { |
43 | Some(("false" , _)) => exit(1), |
44 | Some(("true" , _)) => exit(0), |
45 | _ => unreachable!("parser should ensure only valid subcommand names are used" ), |
46 | } |
47 | } |
48 | |