Skip to content

Commit

Permalink
cli: -e now stops on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
lpenz committed Sep 28, 2024
1 parent 4edae09 commit 57948a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub struct Cli {
#[arg(short = 'z', long = "until-success")]
pub until_success: bool,

/// Loop until the command exists with a failure
#[arg(short = 'e', long = "until-failure")]
pub until_failure: bool,

/// The command to run
#[clap(value_parser, required = true)]
pub command: Vec<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ pub async fn run_once(cli: &Cli, last_rundata: RunData, pb: &mut Progbar) -> Res
pub async fn run_loop(cli: &Cli) -> Result<()> {
let mut pb = Progbar::default();
let mut last_rundata = run_once(cli, RunData::default(), &mut pb).await?;
if cli.until_success && last_rundata.success() {
if cli.until_success && last_rundata.success() || cli.until_failure && !last_rundata.success() {
return Ok(());
}
let cli_period = time::Duration::from_secs(cli.period);
loop {
let rundata = run_once(cli, last_rundata, &mut pb).await?;
if cli.until_success && rundata.success() {
if cli.until_success && rundata.success() || cli.until_failure && !rundata.success() {
return Ok(());
}
last_rundata = rundata;
Expand Down

0 comments on commit 57948a8

Please sign in to comment.