use crate::path;
use clap::Parser;
use std::path::{Path, PathBuf};
use std::process::Command;
#[derive(Parser)]
pub struct Args {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
}
pub fn run(args: &Args) {
let exe = match find_gdb(&path::config_dir()) {
Some(p) => p,
None => {
eprintln!("❌ m68k-elf-gdb not found. Run `sgdkx install` to download it.");
std::process::exit(1);
}
};
let status = Command::new(&exe)
.args(&args.args)
.status()
.expect("Failed to run m68k-elf-gdb");
std::process::exit(status.code().unwrap_or(1));
}
pub fn find_gdb(config_dir: &Path) -> Option<PathBuf> {
let exe_name = if cfg!(target_os = "windows") {
"m68k-elf-gdb.exe"
} else {
"m68k-elf-gdb"
};
let exe = config_dir.join("m68k-elf-gdb").join("bin").join(exe_name);
exe.exists().then_some(exe)
}