From 1218705fd52771a902eb6c64762623d0c6a13173 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Fri, 27 Sep 2024 12:16:23 -0500 Subject: refactor: merge Check into Status type --- src/service/systemd.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/service/systemd.rs') diff --git a/src/service/systemd.rs b/src/service/systemd.rs index 2e3b74c..45f3bf9 100644 --- a/src/service/systemd.rs +++ b/src/service/systemd.rs @@ -2,7 +2,7 @@ use std::{fmt::Display, process::Command}; use serde::Deserialize; -use crate::{Check, Error, Status}; +use crate::{Error, Status}; #[derive(Debug, Clone, Deserialize)] pub struct Systemd { @@ -16,18 +16,20 @@ impl Display for Systemd { } impl Systemd { - pub async fn check(&self) -> Result { + pub async fn check(&self) -> Result { let output = Command::new("systemctl") .arg("is-active") .arg(&self.service) .output()?; - let stdout = String::from_utf8_lossy(&output.stdout).to_string(); - Ok((!output.status.success()) - .then(|| Check { - status: Status::Fail, - output: Some(format!("Service state: {}", stdout.trim())), - }) - .unwrap_or_default()) + let status = match output.status.success() { + true => Status::Pass, + false => { + let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string(); + Status::Fail(Some(format!("Service state: {}", stdout))) + } + }; + + Ok(status) } } -- cgit v1.2.3-70-g09d2