use super::systemd::SYSTEMD_UNIT_PATTERN;
#[derive(Debug)]
pub(crate) enum RestartStatus {
NotSystemd,
NoUnitsMatched,
Scheduled,
SpawnFailed(String),
}
impl RestartStatus {
pub(super) fn restart_clause(&self) -> String {
match self {
RestartStatus::Scheduled => String::new(),
RestartStatus::NotSystemd => "Binary updated on disk; restart \
the process / relaunch to load the new version."
.to_string(),
RestartStatus::NoUnitsMatched => format!(
"Binary updated on disk, but no \
systemd units matched `{SYSTEMD_UNIT_PATTERN}` at system or user level \
— your daemon (if any) was not restarted. Restart it manually with \
`systemctl --user restart {SYSTEMD_UNIT_PATTERN}` (if installed as a \
user service) or `systemctl restart <your-unit>` (if a system service), \
or relaunch if running standalone."
),
RestartStatus::SpawnFailed(err) => format!(
"Binary updated on disk, but \
scheduling the systemd restart failed ({err}). Restart your daemon \
manually with `systemctl --user restart {SYSTEMD_UNIT_PATTERN}` \
(if a user service) or `systemctl restart {SYSTEMD_UNIT_PATTERN}` \
(if a system service)."
),
}
}
pub(super) fn user_message(&self, current: &str, latest: &str) -> String {
let clause = self.restart_clause();
if clause.is_empty() {
format!("Evolved from v{current} to v{latest}.")
} else {
format!("Evolved from v{current} to v{latest}. {clause}")
}
}
}