diff --git a/src/main.rs b/src/main.rs index d4af30f..89cad96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,19 +3,100 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { - // TODO: - // - run over until succeeds - // - run over until fails - // - run over until stdout match (literal, regex) - // - run over until stderr match (literal, regex) - // - run over until other command succeeds - // - run over until other command fails - // - per run timeout - // - global timeout - // - max iterations - // - sleep + #[command(subcommand)] + command: Command, + + /// Global timeout in seconds + #[arg(short='T', long, default_value = None)] + timeout: Option, + + /// Per-iteration timeout in seconds + #[arg(short='t', long, default_value = None)] + per_run_timeout: Option, + + /// Maximum number of iterations + #[arg(short, long, default_value = None)] + max_iterations: Option, + + /// Delay between iterations in seconds + #[arg(short, long, default_value_t = 1)] + delay: u64, + + /// Consume stdin in it's entirety and propagate a copy to each command execution + #[arg(long)] + consume_stdin: bool, } +#[derive(clap::Subcommand, Debug)] +enum Command { + /// Run command multiple times until it succeeds + UntilSucceeds { + /// Command to run + #[arg(required = true)] + cmd: Vec, + }, + + /// Run command multiple times until it fails + UntilFails { + /// Command to run + #[arg(required = true)] + cmd: Vec, + }, + + /// Run command multiple times until its stdout matches a pattern + UntilStdoutMatch { + /// Command to run + #[arg(required = true)] + cmd: Vec, + + /// Pattern to match (literal) + #[arg(long)] + literal: Option, + + /// Pattern to match (regex) + #[arg(long)] + regex: Option, + }, + + /// Run command multiple times until its stderr matches a pattern + UntilStderrMatch { + /// Command to run + #[arg(required = true)] + cmd: Vec, + + /// Pattern to match (literal) + #[arg(long)] + literal: Option, + + /// Pattern to match (regex) + #[arg(long)] + regex: Option, + }, + + /// Run command multiple times until another command succeeds + UntilOtherCommandSucceeds { + /// Command to run + #[arg(required = true)] + cmd: Vec, + + /// Other command to check + #[arg(long, required = true)] + other_cmd: Vec, + }, + + /// Run command multiple times until another command fails + UntilOtherCommandFails { + /// Command to run + #[arg(required = true)] + cmd: Vec, + + /// Other command to check + #[arg(long, required = true)] + other_cmd: Vec, + }, +} + + fn main() -> Result<(), Box> { let args = Args::parse();