use lean_ctx::core::cache::SessionCache;
use lean_ctx_server::tools::{CrpMode, ctx_overview};
pub(crate) fn cmd_overview(args: &[String]) {
let project_root = super::common::detect_project_root(args);
let task = positional_value(args);
let json = args.iter().any(|a| a == "--json");
let local = || {
let cache = SessionCache::new();
ctx_overview::handle(&cache, task.as_deref(), Some(&project_root), CrpMode::Off).0
};
let run = super::common::CliToolRun::new("ctx_overview", &project_root, None);
if json {
let released = run.human_facing().deliver_json(|| {
let out = local();
let payload = serde_json::json!({
"project_root": project_root,
"task": task,
"output": out,
});
serde_json::to_string_pretty(&payload).unwrap_or(out)
});
match released {
Ok(document) => super::common::print_released(&document),
Err(reason) => super::common::exit_withheld(&reason),
}
} else {
let out = run.deliver_text(local);
super::common::print_released(&out);
}
}
fn positional_value(args: &[String]) -> Option<String> {
for a in args {
if a.starts_with("--") {
continue;
}
return Some(a.clone());
}
None
}