2022-05-23 10:50:11 -05:00
|
|
|
use std::path::PathBuf;
|
2021-10-11 20:51:33 +01:00
|
|
|
use std::process::exit;
|
2021-09-14 21:38:41 +01:00
|
|
|
|
2022-05-23 10:50:11 -05:00
|
|
|
use clap::{value_parser, Arg, Command};
|
2021-09-14 21:38:41 +01:00
|
|
|
|
2022-02-11 21:48:29 -06:00
|
|
|
fn applet_commands() -> [Command<'static>; 2] {
|
2021-11-17 20:20:52 +00:00
|
|
|
[
|
2022-02-11 21:48:29 -06:00
|
|
|
Command::new("true").about("does nothing successfully"),
|
|
|
|
Command::new("false").about("does nothing unsuccessfully"),
|
2021-11-17 20:20:52 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-09-14 21:38:41 +01:00
|
|
|
fn main() {
|
2022-02-14 15:47:20 -06:00
|
|
|
let cmd = Command::new(env!("CARGO_CRATE_NAME"))
|
2022-02-10 11:51:40 -06:00
|
|
|
.multicall(true)
|
2021-11-17 20:20:52 +00:00
|
|
|
.subcommand(
|
2022-02-11 21:48:29 -06:00
|
|
|
Command::new("busybox")
|
2022-02-10 11:51:40 -06:00
|
|
|
.arg_required_else_help(true)
|
2021-11-17 20:20:52 +00:00
|
|
|
.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")
|
2022-05-23 10:50:11 -05:00
|
|
|
.value_parser(value_parser!(PathBuf))
|
2022-02-09 11:16:34 -06:00
|
|
|
.use_value_delimiter(false),
|
2021-11-17 20:20:52 +00:00
|
|
|
)
|
|
|
|
.subcommands(applet_commands()),
|
2021-09-14 21:38:41 +01:00
|
|
|
)
|
2021-11-17 20:20:52 +00:00
|
|
|
.subcommands(applet_commands());
|
2021-10-15 20:59:33 +01:00
|
|
|
|
2022-02-14 15:47:20 -06:00
|
|
|
let matches = cmd.get_matches();
|
2021-11-17 20:20:52 +00:00
|
|
|
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();
|
2021-09-14 21:38:41 +01:00
|
|
|
}
|
2021-11-17 20:20:52 +00:00
|
|
|
match subcommand {
|
|
|
|
Some(("false", _)) => exit(1),
|
|
|
|
Some(("true", _)) => exit(0),
|
2021-11-12 09:12:32 -06:00
|
|
|
_ => unreachable!("parser should ensure only valid subcommand names are used"),
|
|
|
|
}
|
2021-09-14 21:38:41 +01:00
|
|
|
}
|