use std::collections::BTreeMap;
use std::process::ExitCode;
pub mod audit_report;
pub mod bench;
pub mod bench_gpu_scale;
pub mod compare;
pub mod generate_fixture;
pub mod ingest;
pub mod run_cpu;
pub mod run_gpu;
pub mod s_real_audit;
pub fn parse_flags(args: &[String]) -> Result<BTreeMap<String, String>, String> {
let mut flags: BTreeMap<String, String> = BTreeMap::new();
let mut i = 0;
while i < args.len() {
let arg = &args[i];
if let Some(rest) = arg.strip_prefix("--") {
let (key, value) = if let Some((k, v)) = rest.split_once('=') {
(k.to_string(), v.to_string())
} else {
let next_is_value = args.get(i + 1).is_some_and(|next| !next.starts_with("--"));
if next_is_value {
let value = args[i + 1].clone();
i += 1;
(rest.to_string(), value)
} else {
(rest.to_string(), "true".to_string())
}
};
if flags.insert(key.clone(), value).is_some() {
return Err(format!("flag --{key} given more than once"));
}
i += 1;
} else {
return Err(format!("unexpected positional argument: {arg}"));
}
}
Ok(flags)
}
pub fn require_flag<'a>(
flags: &'a BTreeMap<String, String>,
name: &str,
) -> Result<&'a str, String> {
flags
.get(name)
.map(String::as_str)
.ok_or_else(|| format!("missing required flag --{name}"))
}
pub fn usage_error(message: &str) -> ExitCode {
eprintln!("dsfb-gpu-debug: {message}");
ExitCode::from(1)
}