use crate::babysit::{self, PULSE_SESSION};
use crate::paths::Paths;
use crate::{run, util};
use anyhow::Result;
use std::process::ExitCode;
pub fn cmd_up(paths: &Paths) -> Result<ExitCode> {
if babysit::is_alive(PULSE_SESSION) {
println!("looop: pulse already running ({PULSE_SESSION}) — see it: looop ls");
return Ok(ExitCode::SUCCESS);
}
if babysit::status_exists(PULSE_SESSION) {
babysit::prune(); }
let bin = paths.bin.to_string_lossy().to_string();
babysit::spawn_detached(vec![bin, "_pulse".to_string()], PULSE_SESSION)?;
println!("looop: pulse started ({PULSE_SESSION})");
println!(" see: {}looop ls", paths.looop_hint_env());
println!(" watch: {}looop attach pulse", paths.looop_hint_env());
println!(" stop: {}looop down", paths.looop_hint_env());
Ok(ExitCode::SUCCESS)
}
pub fn cmd_down(_paths: &Paths) -> Result<ExitCode> {
if !babysit::status_exists(PULSE_SESSION) {
println!("looop: no pulse session to stop");
return Ok(ExitCode::SUCCESS);
}
match babysit::kill(PULSE_SESSION) {
Ok(()) => {
babysit::prune();
println!("looop: pulse stopped");
Ok(ExitCode::SUCCESS)
}
Err(e) => {
util::log(&format!("{}down: {e}{}", util::red(), util::rst()));
Ok(ExitCode::from(1))
}
}
}
pub fn cmd_pulse(paths: &Paths) -> Result<ExitCode> {
run::cmd_run(paths)
}