use std::process::ExitCode;
use clap::{Parser, Subcommand};
mod waitsync;
#[derive(Debug, Parser)]
#[command(name = "cbctl", version, about)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
Waitsync(waitsync::WaitsyncArgs),
}
fn main() -> ExitCode {
match Cli::parse().command {
Command::Waitsync(args) => waitsync::run(&args),
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn cli_parse_waitsync_timeout_seconds() {
let cli = Cli::parse_from(["cbctl", "waitsync", "--timeout-seconds", "30"]);
let Command::Waitsync(args) = cli.command;
assert_eq!(args.timeout_seconds, 30);
}
#[test]
fn cli_parse_waitsync_timeout_seconds_short() {
let cli = Cli::parse_from(["cbctl", "waitsync", "-t", "30"]);
let Command::Waitsync(args) = cli.command;
assert_eq!(args.timeout_seconds, 30);
}
#[test]
fn cli_parse_waitsync_default_timeout_seconds() {
let cli = Cli::parse_from(["cbctl", "waitsync"]);
let Command::Waitsync(args) = cli.command;
assert_eq!(args.timeout_seconds, 60);
}
#[test]
fn cli_parse_waitsync_accepts_zero() {
let cli = Cli::parse_from(["cbctl", "waitsync", "-t", "0"]);
let Command::Waitsync(args) = cli.command;
assert_eq!(args.timeout_seconds, 0);
}
#[test]
fn cli_parse_waitsync_rejects_invalid() {
let _ = Cli::try_parse_from(["cbctl", "waitsync", "-t", "-5"]).unwrap_err();
let _ = Cli::try_parse_from(["cbctl", "waitsync", "-t", "abc"]).unwrap_err();
}
}