use super::{AwarenessMap, EcosystemAwareness};

pub struct ScriptAwareness;

impl EcosystemAwareness for ScriptAwareness {
    fn matches(&self, program: &str, _args: &[String]) -> bool {
        let prog = program.split('/').next_back().unwrap_or(program);
        matches!(prog, "bash" | "sh" | "zsh" | "fish")
            || program.ends_with(".sh")
            || program.ends_with(".bash")
    }

    fn extract(&self, _stdout: &str, _stderr: &str, exit_code: i32) -> AwarenessMap {
        let mut map = AwarenessMap::new("script", "execute");
        map.insert("exit_code", exit_code.to_string());
        map.insert("succeeded", (exit_code == 0).to_string());
        map
    }
}
