use crate::home::Home;
#[cfg(any(target_os = "macos", target_os = "linux"))]
use crate::commands::service::{self, State};
#[cfg(any(target_os = "macos", target_os = "linux"))]
pub fn service_lines(home: &Home) -> Vec<(bool, String)> {
let Ok(manager) = service::manager(home) else {
return Vec::new();
};
let (Ok(state), Ok(path)) = (manager.state(), manager.file_path()) else {
return Vec::new();
};
let ok = match state {
State::NotInstalled => return Vec::new(),
State::Running => true,
_ => false,
};
let mut lines = vec![(ok, format!("service {}", state.describe(&path)))];
let findings = match crate::install::hook_binary() {
Ok(binary) => service::read_back(manager.as_ref(), &binary, home.root()),
Err(e) => vec![format!("cannot be compared: {e:#}")],
};
lines.extend(findings.into_iter().map(|finding| {
(
false,
format!(
"service file {} {finding}; `openmoat proxy install` writes it again",
path.display()
),
)
}));
lines
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
pub fn service_lines(_home: &Home) -> Vec<(bool, String)> {
Vec::new()
}