use std::time::Instant;
use agent_loadout_core::diagnostics::log::{self, Logger};
use agent_loadout_core::paths::LoadoutHome;
use agent_loadout_core::{CoreError, Env};
use clap::ArgMatches;
const QUIET: [&str; 2] = ["completions", "exec"];
pub fn command_name(matches: &ArgMatches) -> String {
let mut words = Vec::new();
let mut current = matches;
while let Some((name, sub)) = current.subcommand() {
words.push(name);
current = sub;
}
words.join(" ")
}
pub fn logged(name: &str) -> bool {
let first = name.split(' ').next().unwrap_or_default();
!QUIET.contains(&first)
}
pub fn start(env: &Env, home: &LoadoutHome, name: &str) -> bool {
let Some(logger) = Logger::for_home(env, home, "cli") else {
return false;
};
log::install(logger);
log::event("command.start", &[("name", &name)]);
true
}
pub fn finish(name: &str, result: &Result<u8, CoreError>, started: Instant) {
log::finished(
"command.end",
name,
result.as_ref().err().map(CoreError::code),
started,
);
log::uninstall();
}