#![deny(clippy::print_stdout, clippy::print_stderr)]
mod cli;
mod commands;
mod display;
mod exit;
mod output;
use cli::Command;
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
let code = match cli::parse(&args) {
Ok(cmd) => run(cmd),
Err(usage) => {
output::stderr(&usage);
exit::USAGE
}
};
std::process::exit(code);
}
fn run(cmd: Command) -> i32 {
match cmd {
Command::Version => {
let report = format!(
"brygge {}\nIR contract version: {}\n",
env!("CARGO_PKG_VERSION"),
brygge_ir::version::CURRENT
);
if let Some(code) = output::stdout(&report) {
return code;
}
exit::CLEAN
}
Command::Help => {
if let Some(code) = output::stdout(&format!("{}\n", cli::USAGE)) {
return code;
}
exit::CLEAN
}
Command::Decode {
kind,
source,
out,
infer_renames,
reconstruct_refs,
format,
} => commands::run_decode(kind, &source, &out, infer_renames, reconstruct_refs, format),
Command::Inspect {
artifact,
atoms,
format,
} => commands::run_inspect(&artifact, atoms, format),
Command::Verify {
artifact,
against_source,
format,
} => commands::run_verify(&artifact, against_source.as_deref(), format),
}
}