mod cli;
mod commands;
mod exit;
mod progress;
use std::io::Write as _;
use std::process::ExitCode;
use clap::Parser as _;
use crate::cli::{Cli, Command};
fn main() -> ExitCode {
let cli = Cli::parse();
let result = match &cli.command {
Command::Scan(args) => commands::scan::run(args, &cli.global),
};
match result {
Ok(outcome) => exit::code(outcome.exit_code()),
Err(error) => {
report(&error);
exit::code(exit::EXECUTION_ERROR)
}
}
}
fn report(error: &anyhow::Error) {
let mut stderr = std::io::stderr().lock();
let _ = writeln!(stderr, "error: {error}");
for cause in error.chain().skip(1) {
let _ = writeln!(stderr, " caused by: {cause}");
}
}