#![feature(rustc_private, yggdrasil_os, let_chains)]

use std::{
    io,
    process::{Command, ExitCode},
};

use clap::Parser;
use tracer::CommandTracer;

pub mod format;
pub mod tracer;

#[derive(Debug, Parser)]
struct Args {
    command: String,
    args: Vec<String>,
}

fn run(args: &Args) -> io::Result<()> {
    let mut command = Command::new(&args.command);
    command.args(&args.args);
    let tracer = CommandTracer::spawn(command)?;
    tracer.run(format::format_syscall)
}

fn main() -> ExitCode {
    let args = Args::parse();
    match run(&args) {
        Ok(()) => ExitCode::SUCCESS,
        Err(error) => {
            eprintln!("{}: {error}", args.command);
            ExitCode::FAILURE
        }
    }
}
