From eac131ec71ba6caed180f5a1fba5d210361689e6 Mon Sep 17 00:00:00 2001 From: Ella Dunbar Date: Tue, 15 Jul 2025 20:26:16 -0500 Subject: [PATCH] WIP: pacman --- src/lib.rs | 2 +- src/pacman/mod.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ff7761f..2e9d4a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ pub struct Package { pub trait Manager { fn command_name(&self) -> OsString; - fn command_exists(&self) -> Result<(), &str> + fn test_command(&mut self) -> Result<(), String> where Self: Sized; fn remote_search(&self, query: &str) -> Result, &str>; diff --git a/src/pacman/mod.rs b/src/pacman/mod.rs index 450191d..499c20b 100644 --- a/src/pacman/mod.rs +++ b/src/pacman/mod.rs @@ -2,28 +2,34 @@ use crate::*; use std::str::FromStr; use std::{ffi::OsString, process::Command}; -pub struct Pacman; +pub struct Pacman { + command_exists: bool, +} impl Manager for Pacman { fn command_name(&self) -> OsString { return OsString::from_str("pacman").unwrap(); } - fn command_exists(&self) -> Result<(), &str> + fn test_command(&mut self) -> Result<(), String> where Self: Sized { - let output = Command::new("which").arg("pacman").output(); + if self.command_exists { return Ok(()); } + let output = Command::new("which").arg(self.command_name()).output(); match output { Ok(output) => { if output.status.success() { + self.command_exists = true; return Ok(()); } else { - return Err("pacman could not be found in path."); + let err = format!("{} could not be found in path", self.command_name().to_string_lossy()); + return Err(err); } } - Err(_) => return Err("Existence check could not be run."), + Err(_) => return Err("Existence check could not be run.".to_string()), } } fn remote_search(&self, query: &str) -> Result, &str> { + if self.command_exists() let output = Command::new } }