use crate::cmd::common::{create_temp_mountpoint, setup_signal_handler, unmount_internal};
use agentignore::fs::AgentFS;
use std::path::PathBuf;
use std::process::Command as ProcessCommand;
pub fn run(command: Vec<String>, source: Option<PathBuf>, show_config_files: bool) {
crate::cmd::doctor::check_prerequisites(true);
let source = source.unwrap_or_else(|| std::env::current_dir().unwrap());
let source = source.canonicalize().expect("source path must exist");
let mountpoint = create_temp_mountpoint(&source);
setup_signal_handler(Some(mountpoint.clone()), true);
println!("Mounting {:?} → {:?}", source, mountpoint);
let fs = AgentFS::with_config(source.clone(), None, show_config_files);
let mp_clone = mountpoint.clone();
let mount_handle = std::thread::spawn(move || {
fuser::mount2(fs, &mp_clone, &fuser::Config::default()).expect("mount failed");
});
std::thread::sleep(std::time::Duration::from_millis(100));
let program = &command[0];
let args = &command[1..];
let status = ProcessCommand::new(program)
.args(args)
.current_dir(&mountpoint)
.env("PWD", &mountpoint) .status()
.expect("failed to execute command");
unmount_internal(&mountpoint);
let _ = std::fs::remove_dir(&mountpoint);
let _ = mount_handle.join();
std::process::exit(status.code().unwrap_or(1));
}