Re-add --kill flag for compatibility

--kill translates to --signal SIGKILL
This commit is contained in:
Chris Aumann 2017-04-02 21:13:44 +02:00
parent 627f828b3c
commit 4763de3790
1 changed files with 88 additions and 72 deletions

View File

@ -33,8 +33,7 @@ pub fn clear_screen() {
#[allow(unknown_lints)]
#[allow(or_fun_call)]
pub fn get_args() -> Args {
let args =
App::new("watchexec")
let args = App::new("watchexec")
.version(crate_version!())
.about("Execute commands when watched files change")
.arg(Arg::with_name("command")
@ -68,6 +67,10 @@ pub fn get_args() -> Args {
.takes_value(true)
.number_of_values(1)
.value_name("signal"))
.arg(Arg::with_name("kill")
.help("Send SIGKILL to child processes (deprecated, use -s SIGKILL instead)")
.short("k")
.long("kill"))
.arg(Arg::with_name("debug")
.help("Print debugging messages to stderr")
.short("d")
@ -102,9 +105,16 @@ pub fn get_args() -> Args {
.arg(Arg::with_name("once").short("1").hidden(true))
.get_matches();
let cmd = values_t!(args.values_of("command"), String).unwrap().join(" ");
let cmd = values_t!(args.values_of("command"), String)
.unwrap()
.join(" ");
let paths = values_t!(args.values_of("path"), String).unwrap_or(vec![String::from(".")]);
let signal = args.value_of("signal").map(str::to_string); // Convert Option<&str> to Option<String>
// Treat --kill as --signal SIGKILL (for compatibility with older syntax)
let signal = match args.is_present("kill") {
true => Some("SIGKILL".to_string()),
false => args.value_of("signal").map(str::to_string), // Convert Option<&str> to Option<String>
};
let mut filters = values_t!(args.values_of("filter"), String).unwrap_or(vec![]);
@ -138,6 +148,12 @@ pub fn get_args() -> Args {
.exit();
}
if signal.is_some() && args.is_present("kill") {
// TODO: Error::argument_conflict() might be the better fit, usage was unclear, though
Error::value_validation_auto(format!("--kill and --signal is ambiguous.\n Hint: Use only '--signal SIGKILL' without --kill"))
.exit();
}
Args {
cmd: cmd,
paths: paths,