WIP: pacman

This commit is contained in:
Ella Dunbar 2025-07-15 20:26:16 -05:00
parent 1f3ea50d6a
commit eac131ec71
2 changed files with 12 additions and 6 deletions

View file

@ -11,7 +11,7 @@ pub struct Package {
pub trait Manager { pub trait Manager {
fn command_name(&self) -> OsString; fn command_name(&self) -> OsString;
fn command_exists(&self) -> Result<(), &str> fn test_command(&mut self) -> Result<(), String>
where where
Self: Sized; Self: Sized;
fn remote_search(&self, query: &str) -> Result<Vec<Package>, &str>; fn remote_search(&self, query: &str) -> Result<Vec<Package>, &str>;

View file

@ -2,28 +2,34 @@ use crate::*;
use std::str::FromStr; use std::str::FromStr;
use std::{ffi::OsString, process::Command}; use std::{ffi::OsString, process::Command};
pub struct Pacman; pub struct Pacman {
command_exists: bool,
}
impl Manager for Pacman { impl Manager for Pacman {
fn command_name(&self) -> OsString { fn command_name(&self) -> OsString {
return OsString::from_str("pacman").unwrap(); return OsString::from_str("pacman").unwrap();
} }
fn command_exists(&self) -> Result<(), &str> fn test_command(&mut self) -> Result<(), String>
where where
Self: Sized { 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 { match output {
Ok(output) => { Ok(output) => {
if output.status.success() { if output.status.success() {
self.command_exists = true;
return Ok(()); return Ok(());
} else { } 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<Vec<Package>, &str> { fn remote_search(&self, query: &str) -> Result<Vec<Package>, &str> {
if self.command_exists()
let output = Command::new let output = Command::new
} }
} }