use clap::{Parser, ValueEnum};
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(crate) enum WaitStrategyOpt {
#[value(name = "busy-spin")]
BusySpin,
#[value(name = "blocking-wait")]
BlockingWait,
}
#[derive(Debug, Clone, Parser)]
#[command(name = "live", about = "Live market simulation server")]
pub(crate) struct Cli {
#[arg(
long = "ring-size",
default_value_t = 8192 * 4,
value_parser = parse_pow2_usize
)]
pub(crate) ring_size_pow2: usize,
#[arg(long, default_value_t = 100)]
pub(crate) binary_yes_max_price_ticks: u16,
#[arg(long, value_enum, default_value_t = WaitStrategyOpt::BusySpin)]
pub(crate) wait_strategy: WaitStrategyOpt,
}
pub(crate) fn parse_pow2_usize(s: &str) -> Result<usize, String> {
let v: usize = s
.parse()
.map_err(|_| format!("invalid integer for --ring-size: {s}"))?;
if v == 0 || (v & (v - 1)) != 0 {
return Err(format!(
"--ring-size must be a power of 2 (e.g. 32768); got {v}"
));
}
Ok(v)
}