From aa5ee4497eb06c171321ff69a6740dde1c67a8ca Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Tue, 6 Feb 2024 07:38:40 +0100 Subject: [PATCH] CommandList: add a method to run all the commands in foreground (#25) --- src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fd92d06..ac292e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,7 @@ //! ## A basic implementation //! //! ```rust,no_run -//! use std::process::Command; +//! use std::process::{Command, ExitStatus}; //! use xtask_watch::{ //! anyhow::Result, //! clap, @@ -559,6 +559,18 @@ impl CommandList { } } } + + /// Run all the commands sequentially using [`std::process::Command::status`] and stop at the + /// first failure. + pub fn status(&mut self) -> io::Result { + for process in self.commands.lock().expect("not poisoned").iter_mut() { + let exit_status = process.status()?; + if !exit_status.success() { + return Ok(exit_status); + } + } + Ok(Default::default()) + } } #[cfg(test)]