Merge branch 'testing'
This commit is contained in:
commit
df1c723b15
@ -6,90 +6,83 @@ use super::*;
|
|||||||
|
|
||||||
/// Creates a `PackageManager` struct to hold in the needed data
|
/// Creates a `PackageManager` struct to hold in the needed data
|
||||||
/// to run our commands.
|
/// to run our commands.
|
||||||
// TODO: figure out a better way to store and access the data.
|
|
||||||
// Maybe a Vec?
|
|
||||||
// Currently actions that require multiple inputs will not work
|
|
||||||
// such as `apt-get update && apt-get upgrade`
|
|
||||||
// Option<Vec<String>> used to handle package managers that don't support
|
|
||||||
// that type of action at all, user will be notified.
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct PackageManager {
|
pub struct PackageManager<'a> {
|
||||||
pub name: String,
|
pub name: &'a str,
|
||||||
pub search: Option<Vec<String>>,
|
pub search: Option<Vec<&'a str>>,
|
||||||
pub install: Option<Vec<String>>,
|
pub install: Option<Vec<&'a str>>,
|
||||||
pub uninstall: Option<Vec<String>>,
|
pub uninstall: Option<Vec<&'a str>>,
|
||||||
pub sup: Option<Vec<String>>,
|
pub sup: Option<Vec<&'a str>>,
|
||||||
pub purge: Option<Vec<String>>,
|
pub purge: Option<Vec<&'a str>>,
|
||||||
pub update: Option<Vec<String>>,
|
pub update: Option<Vec<&'a str>>,
|
||||||
pub upgrade: Option<Vec<String>>,
|
pub upgrade: Option<Vec<&'a str>>,
|
||||||
pub cache_clear: Option<Vec<String>>,
|
pub cache_clear: Option<Vec<&'a str>>,
|
||||||
pub complete_cache_clear: Option<Vec<String>>,
|
pub complete_cache_clear: Option<Vec<&'a str>>,
|
||||||
pub exe: PathBuf,
|
pub exe: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This holds the various implementations of `PackageManagers` so far.
|
/// This holds the various implementations of `PackageManagers` so far.
|
||||||
impl PackageManager {
|
impl<'a> PackageManager<'a> {
|
||||||
pub fn pacmatic() -> PackageManager {
|
pub fn pacmatic() -> PackageManager<'a> {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "pacmatic".to_string(),
|
name: "pacmatic",
|
||||||
search: Some(vec!["pacmatic".to_string(), "-Ss".to_string()]),
|
search: Some(vec!["pacmatic", "-Ss"]),
|
||||||
install: Some(vec!["pacmatic".to_string(), "-S".to_string()]),
|
install: Some(vec!["pacmatic", "-S"]),
|
||||||
uninstall: Some(vec!["pacmatic".to_string(), "-R".to_string()]),
|
uninstall: Some(vec!["pacmatic", "-R"]),
|
||||||
sup: Some(vec!["pacmatic".to_string(), "-Syu".to_string()]),
|
sup: Some(vec!["pacmatic", "-Syu"]),
|
||||||
//sup: Some(vec!["pacmatic".to_string(), "-Sy".to_string(), "-Su".to_string()]),
|
//sup: Some(vec!["pacmatic", "-Sy", "-Su"]),
|
||||||
purge: Some(vec!["pacmatic".to_string(), "-Rdns".to_string()]),
|
purge: Some(vec!["pacmatic", "-Rdns"]),
|
||||||
upgrade: Some(vec!["pacmatic".to_string(), "-Su".to_string()]),
|
upgrade: Some(vec!["pacmatic", "-Su"]),
|
||||||
update: Some(vec!["pacmatic".to_string(), "-Sy".to_string()]),
|
update: Some(vec!["pacmatic", "-Sy"]),
|
||||||
cache_clear: Some(vec!["pacmatic".to_string(), "-Sc".to_string()]),
|
cache_clear: Some(vec!["pacmatic", "-Sc"]),
|
||||||
complete_cache_clear: Some(vec!["pacmatic".to_string(), "-Scc".to_string()]),
|
complete_cache_clear: Some(vec!["pacmatic", "-Scc"]),
|
||||||
exe: PathBuf::from("/bin/pacmatic"),
|
exe: PathBuf::from("/bin/pacmatic"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn pacman() -> PackageManager<'a> {
|
||||||
pub fn pacman() -> PackageManager {
|
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "pacman".to_string(),
|
name: "pacman",
|
||||||
search: Some(vec!["pacman".to_string(), "-Ss".to_string()]),
|
search: Some(vec!["pacman", "-Ss"]),
|
||||||
install: Some(vec!["pacman".to_string(), "-S".to_string()]),
|
install: Some(vec!["pacman", "-S"]),
|
||||||
uninstall: Some(vec!["pacman".to_string(), "-R".to_string()]),
|
uninstall: Some(vec!["pacman", "-R"]),
|
||||||
sup: Some(vec!["pacman".to_string(), "-Syu".to_string()]),
|
sup: Some(vec!["pacman", "-Syu"]),
|
||||||
purge: Some(vec!["pacman".to_string(), "-Rdns".to_string()]),
|
purge: Some(vec!["pacman", "-Rdns"]),
|
||||||
upgrade: Some(vec!["pacman".to_string(), "-Su".to_string()]),
|
upgrade: Some(vec!["pacman", "-Su"]),
|
||||||
update: Some(vec!["pacman".to_string(), "-Sy".to_string()]),
|
update: Some(vec!["pacman", "-Sy"]),
|
||||||
cache_clear: Some(vec!["pacman".to_string(), "-Sc".to_string()]),
|
cache_clear: Some(vec!["pacman", "-Sc"]),
|
||||||
complete_cache_clear: Some(vec!["pacman".to_string(), "-Scc".to_string()]),
|
complete_cache_clear: Some(vec!["pacman", "-Scc"]),
|
||||||
exe: PathBuf::from("/bin/pacman"),
|
exe: PathBuf::from("/bin/pacman"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apt() -> PackageManager {
|
pub fn apt() -> PackageManager<'a> {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "apt".to_string(),
|
name: "apt",
|
||||||
search: Some(vec!["apt".to_string(), "search".to_string()]),
|
search: Some(vec!["apt", "search"]),
|
||||||
install: Some(vec!["apt".to_string(), "install".to_string()]),
|
install: Some(vec!["apt", "install"]),
|
||||||
uninstall:Some(vec!["apt".to_string(), "remove".to_string()]),
|
uninstall:Some(vec!["apt", "remove"]),
|
||||||
sup: Some(vec!["apt".to_string(), "update".to_string(), "upgrade".to_string()]),
|
sup: Some(vec!["apt", "update", "upgrade"]),
|
||||||
purge: Some(vec!["apt".to_string(), "purge".to_string()]),
|
purge: Some(vec!["apt", "purge"]),
|
||||||
upgrade: Some(vec!["apt".to_string(), "upgrade".to_string()]),
|
upgrade: Some(vec!["apt", "upgrade"]),
|
||||||
update: Some(vec!["apt".to_string(), "update".to_string()]),
|
update: Some(vec!["apt", "update"]),
|
||||||
cache_clear: Some(vec!["apt".to_string(), "clean".to_string()]),
|
cache_clear: Some(vec!["apt", "clean"]),
|
||||||
complete_cache_clear: Some(vec!["apt-get".to_string(), "autoclean".to_string()]),
|
complete_cache_clear: Some(vec!["apt-get", "autoclean"]),
|
||||||
exe: PathBuf::from("/usr/bin/apt"),
|
exe: PathBuf::from("/usr/bin/apt"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn xbps() -> PackageManager {
|
pub fn xbps() -> PackageManager<'a> {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "xbps".to_string(),
|
name: "xbps",
|
||||||
search: Some(vec!["xbps-query".to_string(), "-Rs".to_string()]),
|
search: Some(vec!["xbps-query", "-Rs"]),
|
||||||
install: Some(vec!["xbps-install".to_string(), "-S".to_string()]),
|
install: Some(vec!["xbps-install", "-S"]),
|
||||||
uninstall: Some(vec!["xbps-remove".to_string()]),
|
uninstall: Some(vec!["xbps-remove"]),
|
||||||
sup: Some(vec!["xbps-install".to_string(), "-Su".to_string()]),
|
sup: Some(vec!["xbps-install", "-Su"]),
|
||||||
purge: Some(vec!["xbps-remove".to_string(), "-R".to_string()]),
|
purge: Some(vec!["xbps-remove", "-R"]),
|
||||||
upgrade: Some(vec!["xbps-install".to_string(), "-Su".to_string()]),
|
upgrade: Some(vec!["xbps-install", "-Su"]),
|
||||||
update: Some(vec!["xbps-install".to_string()]),
|
update: Some(vec!["xbps-install"]),
|
||||||
cache_clear: Some(vec!["xbps-remove".to_string(), "-0".to_string()]),
|
cache_clear: Some(vec!["xbps-remove", "-0"]),
|
||||||
complete_cache_clear: Some(vec!["xbps-remove".to_string(), "-0".to_string()]),
|
complete_cache_clear: Some(vec!["xbps-remove", "-0"]),
|
||||||
exe: PathBuf::from("bin/xbps-install"),
|
exe: PathBuf::from("bin/xbps-install"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,17 +100,15 @@ impl PackageManager {
|
|||||||
/// Pulls the first line out of the default.conf and loads that.
|
/// Pulls the first line out of the default.conf and loads that.
|
||||||
/// If it doesn't recognize the file it will tell the user that there's an
|
/// If it doesn't recognize the file it will tell the user that there's an
|
||||||
/// issue before exiting.
|
/// issue before exiting.
|
||||||
pub fn read_default() -> PackageManager {
|
pub fn read_default<'a>() -> PackageManager<'a> {
|
||||||
let file = File::open("default.conf").unwrap();
|
let file = File::open("default.conf").unwrap();
|
||||||
let buffered = BufReader::new(file);
|
let buffered = BufReader::new(file);
|
||||||
for line in buffered.lines() {
|
for line in buffered.lines() {
|
||||||
match &*line.unwrap() {
|
match &*line.unwrap() {
|
||||||
"pacmatic" => return PackageManager::pacmatic(),
|
"pacmatic" => return PackageManager::pacmatic(),
|
||||||
/*
|
|
||||||
"pacman" => return PackageManager::pacman(),
|
"pacman" => return PackageManager::pacman(),
|
||||||
"apt" => return PackageManager::apt(),
|
"apt" => return PackageManager::apt(),
|
||||||
"xbps" => return PackageManager::xbps(),
|
"xbps" => return PackageManager::xbps(),
|
||||||
*/
|
|
||||||
_ => {
|
_ => {
|
||||||
println!("Default either not set or has been changed");
|
println!("Default either not set or has been changed");
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user