//! Parse Git CLI arguments and return Git-compatible usage and operation exit codes. use clap::{Parser, error::ErrorKind}; fn main() { if matches!(std::env::args().nth(1).as_deref(), Some("--version" | "version")) { println!("git version {}.sausage", env!("CARGO_PKG_VERSION")); exit(0); } let cli = match git::Cli::try_parse() { Ok(cli) => cli, Err(error) => { let code = if !error.use_stderr() { 0 } else { match error.kind() { ErrorKind::InvalidSubcommand | ErrorKind::MissingSubcommand => 1, _ => 129, } }; let _ = error.print(); exit(code); } }; let code = match git::run(cli) { Ok(code) => code, Err(error) => { eprintln!("fatal: {error}"); 128 } }; exit(code); } fn exit(code: i32) -> ! { #[cfg(target_os = "wasi")] { use std::io::Write; let _ = std::io::stdout().flush(); let _ = std::io::stderr().flush(); wasi::cli::exit::exit_with_code(code as u8); unreachable!("WASI exit returned"); } #[cfg(not(target_os = "wasi"))] std::process::exit(code) }