Skip to content

Commit

Permalink
style: add docs and fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKoralewski committed Sep 24, 2024
1 parent c162bfc commit 0bcf1df
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ const SYSTEMCTL_PATH: &str = "/usr/bin/systemctl";

use bon::Builder;

/// Struct with API calls to systemctl.
///
/// Use the `::default()` impl if you don't need special arguments.
///
/// Use the builder API when you want to specify a custom path to systemctl binary or extra args.
#[derive(Builder, Default, Clone, Debug)]
pub struct SystemCtl {
/// Allows passing global arguments to systemctl like `--user`.
additional_args: Vec<String>,
/// The path to the systemctl binary, by default it's [SYSTEMCTL_PATH]
path: Option<String>
}

Expand All @@ -29,7 +36,7 @@ impl SystemCtl {
}

fn get_path(&self) -> &str {
self.path.as_ref().map(|s| s.as_str()).unwrap_or(SYSTEMCTL_PATH)
self.path.as_deref().unwrap_or(SYSTEMCTL_PATH)
}

/// Invokes `systemctl $args` silently
Expand All @@ -41,10 +48,10 @@ impl SystemCtl {
fn systemctl_capture<'a, 's: 'a, S: IntoIterator<Item = &'a str>>(&'s self, args: S) -> std::io::Result<String> {
let mut child = self.spawn_child(args)?;
match child.wait()?.code() {
Some(code) if code == 0 => {}, // success
Some(code) if code == 1 => {}, // success -> Ok(Unit not found)
Some(code) if code == 3 => {}, // success -> Ok(unit is inactive and/or dead)
Some(code) if code == 4 => {
Some(0) => {}, // success
Some(1) => {}, // success -> Ok(Unit not found)
Some(3) => {}, // success -> Ok(unit is inactive and/or dead)
Some(4) => {
return Err(Error::new(
ErrorKind::PermissionDenied,
"Missing Priviledges or Unit not found",
Expand Down

0 comments on commit 0bcf1df

Please sign in to comment.