pub fn option_value(args: &[String], option: &str) -> Option<String> {
    let mut idx = 0usize;
    while idx + 1 < args.len() {
        if args[idx] == option {
            return Some(args[idx + 1].clone());
        }
        idx += 1;
    }
    None
}

pub fn has_flag(args: &[String], flag: &str) -> bool {
    args.iter().any(|arg| arg == flag)
}

pub fn is_help(arg: &str) -> bool {
    matches!(arg, "--help" | "-h")
}

pub fn print_usage(
    default_bind: &str,
    default_status_report: &str,
    default_runtime_report: &str,
    default_middleware_report: &str,
    default_resource_report: &str,
) {
    println!("robotrt-host commands:");
    println!("  gateway [--bind <addr>] [--source <live|demo|file>] [--report <path>] [--runtime-report <path>] [--middleware-report <path>] [--resource-report <path>] [--once] [--json]");
    println!("  serve-gateway [--bind <addr>] [--source <live|demo|file>] [--report <path>] [--runtime-report <path>] [--middleware-report <path>] [--resource-report <path>] [--once] [--json]");
    println!("  sidecar [--mode <embedded|standalone>] [--bind <addr>] [--advertise-endpoint <addr>] [--source <live|demo|file>] [--report <path>] [--runtime-report <path>] [--middleware-report <path>] [--resource-report <path>] [--node-id <id>] [--tenant <name>] [--namespace <name>] [--sampling-ms <ms>] [--log-level <level>] [--audit-enabled <bool>] [--health-timeout-ms <ms>] [--health-interval-ms <ms>] [--handshake-retries <n>] [--restart-max <n>] [--evidence <path>] [--registry <path>] [--cluster-id <id>] [--cluster-zone <zone>] [--cluster-peers <addr1,addr2>] [--once] [--json]");
    println!("  gateway-sidecar [same as sidecar]");
    println!("  help");
    println!();
    println!("default bind: {default_bind}");
    println!("default status report: {default_status_report}");
    println!("default runtime report: {default_runtime_report}");
    println!("default middleware report: {default_middleware_report}");
    println!("default resource report: {default_resource_report}");
}
