use crate::compsys::ported::_message::_message;
use crate::ported::exec_hooks::dispatch_function_call;
use crate::ported::params::{getiparam, getsparam, setiparam};
pub fn _complete_debug(args: &[String]) -> i32 {
let n = getiparam("_debug_count") + 1;
setiparam("_debug_count", n);
let tmpprefix = getsparam("TMPPREFIX").unwrap_or_else(|| "/tmp/zsh".to_string());
let pid = std::process::id();
let cmd_name = crate::ported::params::getaparam("words")
.and_then(|w| w.first().cloned())
.unwrap_or_default();
let tmp = format!("{}{}{}{}", tmpprefix, pid, basename(&cmd_name), n);
let target = args
.first()
.cloned()
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "_main_complete".to_string());
let ret = dispatch_function_call(&target, &[]).unwrap_or(1);
let _ = _message(&[
"-r".to_string(),
format!("Trace output left in {} (up-history to view)", tmp),
]);
ret
}
fn basename(s: &str) -> String {
s.rsplit('/').next().unwrap_or("").to_string()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn returns_one_without_executor() {
let _g = crate::test_util::global_state_lock();
assert_eq!(_complete_debug(&[]), 1);
}
#[test]
fn increments_debug_count() {
let _g = crate::test_util::global_state_lock();
setiparam("_debug_count", 5);
let _ = _complete_debug(&[]);
assert_eq!(getiparam("_debug_count"), 6);
}
}