Skip to content

Commit

Permalink
Don’t print ending message when using trailers (workaround for #203)
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Dec 29, 2022
1 parent 91f643a commit 8e15284
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ fn main() -> Result<()> {
}
}


let opts = options::get_options(&matches);
let handler = watch::CwHandler::new(opts, quiet, matches.is_present("notif"))?;
let handler = watch::CwHandler::new(
opts,
quiet,
matches.is_present("notif"),
matches.is_present("cmd:trail"),
)?;
watch(&handler)
}
31 changes: 18 additions & 13 deletions src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ impl Handler for CwHandler {
}

impl CwHandler {
pub fn new(mut args: Config, quiet: bool, notify: bool) -> Result<Self> {
let cmd = args.cmd.join(" && ");
let mut final_cmd = cmd.clone();
if !quiet {
#[cfg(unix)]
final_cmd.push_str(r#"; echo "[Finished running. Exit status: $?]""#);
#[cfg(windows)]
final_cmd.push_str(r#" & echo "[Finished running. Exit status: %ERRORLEVEL%]""#);
#[cfg(not(any(unix, windows)))]
final_cmd.push_str(r#" ; echo "[Finished running]""#);
// ^ could be wrong depending on the platform, to be fixed on demand
}
pub fn new(mut args: Config, quiet: bool, notify: bool, trailing: bool) -> Result<Self> {
let cmd = if trailing {
args.cmd[0].clone()
} else {
let cmd = args.cmd.join(" && ");
let mut final_cmd = cmd.clone();
if !quiet {
#[cfg(unix)]
final_cmd.push_str(r#"; echo "[Finished running. Exit status: $?]""#);
#[cfg(windows)]
final_cmd.push_str(r#" & echo "[Finished running. Exit status: %ERRORLEVEL%]""#);
#[cfg(not(any(unix, windows)))]
final_cmd.push_str(r#" ; echo "[Finished running]""#);
// ^ could be wrong depending on the platform, to be fixed on demand
}

args.cmd = vec![final_cmd];
args.cmd = vec![final_cmd];
cmd
};

Ok(Self {
once: args.once,
Expand Down

0 comments on commit 8e15284

Please sign in to comment.