main: fill out argument structs

This commit is contained in:
2025-11-05 19:04:57 +09:00
parent f8b25c3346
commit 71468f38ce
+92 -11
View File
@@ -3,19 +3,100 @@ use clap::Parser;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
struct Args { struct Args {
// TODO: #[command(subcommand)]
// - run over until succeeds command: Command,
// - run over until fails
// - run over until stdout match (literal, regex) /// Global timeout in seconds
// - run over until stderr match (literal, regex) #[arg(short='T', long, default_value = None)]
// - run over until other command succeeds timeout: Option<u64>,
// - run over until other command fails
// - per run timeout /// Per-iteration timeout in seconds
// - global timeout #[arg(short='t', long, default_value = None)]
// - max iterations per_run_timeout: Option<u64>,
// - sleep
/// Maximum number of iterations
#[arg(short, long, default_value = None)]
max_iterations: Option<u64>,
/// 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<String>,
},
/// Run command multiple times until it fails
UntilFails {
/// Command to run
#[arg(required = true)]
cmd: Vec<String>,
},
/// Run command multiple times until its stdout matches a pattern
UntilStdoutMatch {
/// Command to run
#[arg(required = true)]
cmd: Vec<String>,
/// Pattern to match (literal)
#[arg(long)]
literal: Option<String>,
/// Pattern to match (regex)
#[arg(long)]
regex: Option<String>,
},
/// Run command multiple times until its stderr matches a pattern
UntilStderrMatch {
/// Command to run
#[arg(required = true)]
cmd: Vec<String>,
/// Pattern to match (literal)
#[arg(long)]
literal: Option<String>,
/// Pattern to match (regex)
#[arg(long)]
regex: Option<String>,
},
/// Run command multiple times until another command succeeds
UntilOtherCommandSucceeds {
/// Command to run
#[arg(required = true)]
cmd: Vec<String>,
/// Other command to check
#[arg(long, required = true)]
other_cmd: Vec<String>,
},
/// Run command multiple times until another command fails
UntilOtherCommandFails {
/// Command to run
#[arg(required = true)]
cmd: Vec<String>,
/// Other command to check
#[arg(long, required = true)]
other_cmd: Vec<String>,
},
}
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse(); let args = Args::parse();