Print stderr too and only output when warn/error conditions happen.

This commit is contained in:
Bauke 2022-10-31 11:45:36 +01:00
parent 7338b5667a
commit c4c45a0368
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 13 additions and 8 deletions

View File

@ -38,7 +38,10 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
)), )),
}?; }?;
let mut process = command.stdout(Redirection::Pipe).popen()?; let mut process = command
.stderr(Redirection::Merge)
.stdout(Redirection::Pipe)
.popen()?;
let exit_status = process.wait()?; let exit_status = process.wait()?;
let output = { let output = {
let mut output = String::new(); let mut output = String::new();
@ -47,15 +50,17 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
output output
}; };
let (stop, prefix, style) = match (exit_status.success(), hook.on_failure) let (stop, print_output, prefix, style) =
{ match (exit_status.success(), hook.on_failure) {
(true, _) => (false, "", success_style), (true, _) => (false, false, "", success_style),
(false, ExitAction::Continue) => (false, "", warn_style), (false, ExitAction::Continue) => (false, true, "", warn_style),
(false, ExitAction::Stop) => (true, "", error_style), (false, ExitAction::Stop) => (true, true, "", error_style),
}; };
println!("\t{} {}", prefix.style(style), hook_name.style(style)); println!("\t{} {}", prefix.style(style), hook_name.style(style));
if !output.is_empty() && print_output {
println!("{}", output); println!("{}", output);
}
if stop { if stop {
exit(1); exit(1);