use std::process;
use std::str::FromStr;
use vyre_conform::observe::{run_enforce_all, TraceFormat};
fn main() {
match run() {
Ok(code) => process::exit(code),
Err(message) => {
eprintln!("{message}");
process::exit(1);
}
}
}
fn run() -> Result<i32, String> {
let Command::Run(trace_format) = parse_args(std::env::args().skip(1))? else {
print_help();
return Ok(0);
};
let (observed, rendered) = run_enforce_all(trace_format)?;
if let Some(output) = rendered {
eprintln!("{output}");
}
Ok(if observed.report.is_success() { 0 } else { 1 })
}
enum Command {
Help,
Run(TraceFormat),
}
fn parse_args(args: impl Iterator<Item = String>) -> Result<Command, String> {
let mut trace_format = TraceFormat::None;
for arg in args {
if arg == "--help" || arg == "-h" {
return Ok(Command::Help);
}
if let Some(value) = arg.strip_prefix("--trace-format=") {
trace_format = TraceFormat::from_str(value)?;
} else {
return Err(format!("Fix: unknown argument `{arg}`. See --help."));
}
}
Ok(Command::Run(trace_format))
}
fn print_help() {
println!(
"vyre-conform selftest\n\nUSAGE:\n cargo run --bin vyre-conform-selftest -- --trace-format=<format>\n\nOPTIONS:\n --trace-format=<format> one of {}\n --help print this message",
TraceFormat::values()
);
}