//! `adom-chipsmith reveal <file>` — reveal a file in the VS Code Explorer.
//!
//! Delegates to `adom-vscode reveal <abs-path>`. Used by the UI's
//! reveal-in-explorer buttons (each clickable file path in the source row,
//! sign-off HUD, hierarchy header, error toasts) and by AI sessions that want
//! to surface where an artifact ended up on disk.

use anyhow::Result;
use clap::Args as ClapArgs;
use std::path::PathBuf;
use std::process::Command;

#[derive(ClapArgs)]
pub struct Args {
    /// File or directory to reveal in the VS Code Explorer sidebar.
    pub path: PathBuf,
}

pub fn run(args: Args) -> Result<()> {
    let abs = args.path.canonicalize().unwrap_or(args.path.clone());
    let abs_str = abs.to_string_lossy().to_string();

    let status = Command::new("adom-vscode")
        .arg("reveal")
        .arg(&abs_str)
        .status();

    match status {
        Ok(s) if s.success() => {
            super::ok(format!("revealed {abs_str}"));
            Ok(())
        }
        Ok(s) => {
            super::err(format!("adom-vscode reveal exited with status {s}"));
            super::hint("install adom-vscode if missing: it ships from the wiki via auto-discovery");
            std::process::exit(1);
        }
        Err(e) => {
            super::err(format!("could not invoke adom-vscode: {e}"));
            super::hint("install adom-vscode (it provides the VS Code file-explorer reveal hook)");
            std::process::exit(1);
        }
    }
}