From 2d2d5af3553b732237937549dc9b6df28b7c00cb Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Wed, 28 Feb 2024 16:05:45 -0700 Subject: Fix && behavior regression Introduce a switch to break from recite() if the forked process returns a non-zero exit code. The one except to this, is when using semicolons, then we do not care if the previous command failed. --- src/recite.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/recite.rs') diff --git a/src/recite.rs b/src/recite.rs index f21a905..f75cd61 100644 --- a/src/recite.rs +++ b/src/recite.rs @@ -22,7 +22,7 @@ use std::sync::{Arc, Mutex}; /// * `Quiet` - Fork the called process into the background (`&`) /// * `And` - Run the next command only if this one succeeds (`&&`) /// * `String` - String commands together on a single line (`;`) -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] enum Meter { None, // No meter Couplet, // Pipe the output of this command into the next @@ -376,19 +376,19 @@ impl Poem { } // Incant the verse, based on its meter - match verse.meter { + let status = match verse.meter { Meter::None => Meter::incant_none(verse, &mut out)?, Meter::Couplet => Meter::incant_couplet(verse, &mut out)?, Meter::Quiet => Meter::incant_quiet(verse, &mut out, &mut pids)?, Meter::And => Meter::incant_and(verse, &mut out)?, - Meter::String => match Meter::incant_string(verse, &mut out) { - Ok(_) => 0, - Err(e) => { - eprintln!("dwvsh: {}", e.to_string().to_lowercase()); - 1 - } - }, + Meter::String => Meter::incant_string(verse, &mut out)?, }; + + // Don't continue reciting if there was an error, unless the meter + // is String (indicating that errors should be ignored) + if verse.meter != Meter::String && status != 0 { + break; + } } // If we've successfully exited the loop, then all verse's were -- cgit v1.2.3