diff --git a/Cargo.lock b/Cargo.lock index 266e678..ee21263 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,7 @@ dependencies = [ "insta", "log", "predicates", + "shell-escape", "stderrlog", "wait-timeout", "watchexec", @@ -696,6 +697,12 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "shell-escape" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" + [[package]] name = "slab" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index 76c7863..383d6f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ clap = "2.33.1" log = "0.4.8" stderrlog = "0.4.3" watchexec = "=1.14.0" +shell-escape = "0.1.5" [dev-dependencies] assert_cmd = "1.0.1" diff --git a/src/args.rs b/src/args.rs index deff640..659ed50 100644 --- a/src/args.rs +++ b/src/args.rs @@ -167,7 +167,7 @@ pub fn parse() -> ArgMatches<'static> { .arg( Arg::with_name("cmd:trail") .raw(true) - .help("Full command to run. -x and -s will be ignored!") + .help("Full command to run. -x and -s will be ignored!"), ) .after_help(footnote.as_str()), ); diff --git a/src/lib.rs b/src/lib.rs index 7de092a..84a60f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,12 @@ pub fn set_commands(builder: &mut ArgsBuilder, matches: &ArgMatches) { if matches.is_present("cmd:trail") { debug!("trailing command is present, ignore all other command options"); - commands = vec![value_t!(matches, "cmd:trail", String).unwrap_or_else(|e| e.exit())]; + commands = vec![values_t!(matches, "cmd:trail", String) + .unwrap_or_else(|e| e.exit()) + .into_iter() + .map(|arg| shell_escape::escape(arg.into())) + .collect::>() + .join(" ")]; } // Default to `cargo check` diff --git a/src/main.rs b/src/main.rs index 97acdb9..d7e9f4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ //! Watch files in a Cargo project and compile it when they change #![warn(clippy::all)] -use cargo_watch::{args, change_dir, watch::CwHandler, get_options}; +use cargo_watch::{args, change_dir, get_options, watch::CwHandler}; use stderrlog::Timestamp; use watchexec::{error::Result, run::watch}; @@ -16,7 +16,11 @@ fn main() -> Result<()> { stderrlog::new() .quiet(quiet) .verbosity(if debug { 3 } else { 1 }) - .timestamp(if testing { Timestamp::Off } else { Timestamp::Millisecond }) + .timestamp(if testing { + Timestamp::Off + } else { + Timestamp::Millisecond + }) .init() .unwrap();