Multicommand actions should now work
This commit is contained in:
parent
d87d36af3f
commit
985c53237c
@ -10,39 +10,46 @@ impl Config {
|
|||||||
/// Actually runs the package manager. Checks what command was requested
|
/// Actually runs the package manager. Checks what command was requested
|
||||||
/// and loads the appropriate data from the passed `PackageManager`.
|
/// and loads the appropriate data from the passed `PackageManager`.
|
||||||
/// Finally calls the program and passes the appropriate arguments
|
/// Finally calls the program and passes the appropriate arguments
|
||||||
pub fn run(&self, pac: PackageManager) -> Child {
|
pub fn run(&self, pac: PackageManager) {
|
||||||
let prog = match self.action {
|
let vec = match self.action {
|
||||||
Management::Search => (pac.search.0, pac.search.1),
|
Management::Search => pac.search,
|
||||||
Management::Install => (pac.install.0, pac.install.1),
|
Management::Install => pac.install,
|
||||||
Management::Uninstall => (pac.uninstall.0, pac.uninstall.1),
|
Management::Uninstall => pac.uninstall,
|
||||||
Management::Remove => (pac.purge.0, pac.purge.1),
|
Management::Remove => pac.purge,
|
||||||
Management::Update => (pac.update.0, pac.update.1),
|
Management::Update => pac.update,
|
||||||
Management::Upgrade => (pac.upgrade.0, pac.upgrade.1),
|
Management::Upgrade => pac.upgrade,
|
||||||
Management::Full => (pac.sup.0, pac.sup.1),
|
Management::Full => pac.sup,
|
||||||
Management::Clear => (pac.cache_clear.0, pac.cache_clear.1),
|
Management::Clear => pac.cache_clear,
|
||||||
Management::CompleteClear => (pac.complete_cache_clear.0, pac.complete_cache_clear.1),
|
Management::CompleteClear => pac.complete_cache_clear,
|
||||||
};
|
};
|
||||||
|
|
||||||
match (&prog.1, &self.term) {
|
let mut prog = match vec {
|
||||||
(&None, &None) => {
|
None => {
|
||||||
Command::new(&prog.0).spawn().expect(
|
println!("Sorry, your package manager does not support this action");
|
||||||
"Failed to call package manager",
|
std::process::exit(0);
|
||||||
)
|
},
|
||||||
|
Some(x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
|
let command = prog.remove(0);
|
||||||
|
|
||||||
|
let term = match &self.term {
|
||||||
|
&None => "",
|
||||||
|
&Some(ref val) => val,
|
||||||
|
};
|
||||||
|
|
||||||
|
if prog.first().is_none() {
|
||||||
|
let mut child = Command::new(&command).spawn().expect("Broken?");
|
||||||
|
child.wait().expect("Failed to wait on child");
|
||||||
|
}else if self.term.is_none() {
|
||||||
|
while prog.first().is_some() {
|
||||||
|
let mut child = Command::new(&command).arg(prog.remove(0)).spawn().expect("Broken2?");
|
||||||
|
child.wait().expect("Failed to wait on child");
|
||||||
}
|
}
|
||||||
(&Some(ref arg), &None) => {
|
}else {
|
||||||
Command::new(&prog.0).arg(arg).spawn().expect(
|
while prog.first().is_some() {
|
||||||
"Failed to call package manager",
|
let mut child = Command::new(&command).arg(prog.remove(0)).arg(term).spawn().expect("Broken3?");
|
||||||
)
|
child.wait().expect("Failed to wait on child");
|
||||||
}
|
|
||||||
(&Some(ref arg1), &Some(ref arg2)) => {
|
|
||||||
Command::new(&prog.0).arg(arg1).arg(arg2).spawn().expect(
|
|
||||||
"Failed to call package manager",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
println!("{:?}, {:?}", &prog.1, &self.term);
|
|
||||||
println!("Arguments formed incorrectly, no action taken");
|
|
||||||
std::process::exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -7,7 +7,7 @@ use management::Management;
|
|||||||
mod config;
|
mod config;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
|
|
||||||
use std::process::{Command, Child};
|
use std::process::{Command};//, Child};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
@ -22,8 +22,9 @@ fn main() {
|
|||||||
|
|
||||||
if Path::new("default.conf").is_file() {
|
if Path::new("default.conf").is_file() {
|
||||||
let pac = read_default();
|
let pac = read_default();
|
||||||
let mut child = config.run(pac);
|
config.run(pac);
|
||||||
child.wait().expect("Failed to wait on child");
|
//let mut child = config.run(pac);
|
||||||
|
//child.wait().expect("Failed to wait on child");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +33,8 @@ fn main() {
|
|||||||
let aptget = PackageManager::apt();
|
let aptget = PackageManager::apt();
|
||||||
let xbps = PackageManager::xbps();
|
let xbps = PackageManager::xbps();
|
||||||
|
|
||||||
|
|
||||||
let managers: Vec<PackageManager> = vec![pacmatic, pacman, aptget, xbps];
|
let managers: Vec<PackageManager> = vec![pacmatic, pacman, aptget, xbps];
|
||||||
|
//let managers: Vec<PackageManager> = vec![pacmatic];
|
||||||
|
|
||||||
let mut found: bool = false;
|
let mut found: bool = false;
|
||||||
for prog in managers {
|
for prog in managers {
|
||||||
@ -64,8 +65,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
let mut child = config.run(prog);
|
let mut child = config.run(prog);
|
||||||
child.wait().expect("Failed to wait on child");
|
child.wait().expect("Failed to wait on child");
|
||||||
|
*/
|
||||||
|
config.run(prog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,20 @@ use super::*;
|
|||||||
// Maybe a Vec?
|
// Maybe a Vec?
|
||||||
// Currently actions that require multiple inputs will not work
|
// Currently actions that require multiple inputs will not work
|
||||||
// such as `apt-get update && apt-get upgrade`
|
// 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 {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub search: (String, Option<String>),
|
pub search: Option<Vec<String>>,
|
||||||
pub install: (String, Option<String>),
|
pub install: Option<Vec<String>>,
|
||||||
pub uninstall: (String, Option<String>),
|
pub uninstall: Option<Vec<String>>,
|
||||||
pub sup: (String, Option<String>),
|
pub sup: Option<Vec<String>>,
|
||||||
pub purge: (String, Option<String>),
|
pub purge: Option<Vec<String>>,
|
||||||
pub update: (String, Option<String>),
|
pub update: Option<Vec<String>>,
|
||||||
pub upgrade: (String, Option<String>),
|
pub upgrade: Option<Vec<String>>,
|
||||||
pub cache_clear: (String, Option<String>),
|
pub cache_clear: Option<Vec<String>>,
|
||||||
pub complete_cache_clear: (String, Option<String>),
|
pub complete_cache_clear: Option<Vec<String>>,
|
||||||
pub exe: PathBuf,
|
pub exe: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,15 +32,16 @@ impl PackageManager {
|
|||||||
pub fn pacmatic() -> PackageManager {
|
pub fn pacmatic() -> PackageManager {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "pacmatic".to_string(),
|
name: "pacmatic".to_string(),
|
||||||
search: ("pacmatic".to_string(), Some("-Ss".to_string())),
|
search: Some(vec!["pacmatic".to_string(), "-Ss".to_string()]),
|
||||||
install: ("pacmatic".to_string(), Some("-S".to_string())),
|
install: Some(vec!["pacmatic".to_string(), "-S".to_string()]),
|
||||||
uninstall: ("pacmatic".to_string(), Some("-R".to_string())),
|
uninstall: Some(vec!["pacmatic".to_string(), "-R".to_string()]),
|
||||||
sup: ("pacmatic".to_string(), Some("-Syu".to_string())),
|
sup: Some(vec!["pacmatic".to_string(), "-Syu".to_string()]),
|
||||||
purge: ("pacmatic".to_string(), Some("-Rdns".to_string())),
|
//sup: Some(vec!["pacmatic".to_string(), "-Sy".to_string(), "-Su".to_string()]),
|
||||||
upgrade: ("pacmatic".to_string(), Some("-Su".to_string())),
|
purge: Some(vec!["pacmatic".to_string(), "-Rdns".to_string()]),
|
||||||
update: ("pacmatic".to_string(), Some("-Sy".to_string())),
|
upgrade: Some(vec!["pacmatic".to_string(), "-Su".to_string()]),
|
||||||
cache_clear: ("pacmatic".to_string(), Some("-Sc".to_string())),
|
update: Some(vec!["pacmatic".to_string(), "-Sy".to_string()]),
|
||||||
complete_cache_clear: ("pacmatic".to_string(), Some("-Scc".to_string())),
|
cache_clear: Some(vec!["pacmatic".to_string(), "-Sc".to_string()]),
|
||||||
|
complete_cache_clear: Some(vec!["pacmatic".to_string(), "-Scc".to_string()]),
|
||||||
exe: PathBuf::from("/bin/pacmatic"),
|
exe: PathBuf::from("/bin/pacmatic"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,15 +49,15 @@ impl PackageManager {
|
|||||||
pub fn pacman() -> PackageManager {
|
pub fn pacman() -> PackageManager {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "pacman".to_string(),
|
name: "pacman".to_string(),
|
||||||
search: ("pacman".to_string(), Some("-Ss".to_string())),
|
search: Some(vec!["pacman".to_string(), "-Ss".to_string()]),
|
||||||
install: ("pacman".to_string(), Some("-S".to_string())),
|
install: Some(vec!["pacman".to_string(), "-S".to_string()]),
|
||||||
uninstall: ("pacman".to_string(), Some("-R".to_string())),
|
uninstall: Some(vec!["pacman".to_string(), "-R".to_string()]),
|
||||||
sup: ("pacman".to_string(), Some("-Syu".to_string())),
|
sup: Some(vec!["pacman".to_string(), "-Syu".to_string()]),
|
||||||
purge: ("pacman".to_string(), Some("-Rdns".to_string())),
|
purge: Some(vec!["pacman".to_string(), "-Rdns".to_string()]),
|
||||||
upgrade: ("pacman".to_string(), Some("-Su".to_string())),
|
upgrade: Some(vec!["pacman".to_string(), "-Su".to_string()]),
|
||||||
update: ("pacman".to_string(), Some("-Sy".to_string())),
|
update: Some(vec!["pacman".to_string(), "-Sy".to_string()]),
|
||||||
cache_clear: ("pacman".to_string(), Some("-Sc".to_string())),
|
cache_clear: Some(vec!["pacman".to_string(), "-Sc".to_string()]),
|
||||||
complete_cache_clear: ("pacman".to_string(), Some("-Scc".to_string())),
|
complete_cache_clear: Some(vec!["pacman".to_string(), "-Scc".to_string()]),
|
||||||
exe: PathBuf::from("/bin/pacman"),
|
exe: PathBuf::from("/bin/pacman"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,15 +65,15 @@ impl PackageManager {
|
|||||||
pub fn apt() -> PackageManager {
|
pub fn apt() -> PackageManager {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "apt".to_string(),
|
name: "apt".to_string(),
|
||||||
search: ("apt".to_string(), Some("search".to_string())),
|
search: Some(vec!["apt".to_string(), "search".to_string()]),
|
||||||
install: ("apt".to_string(), Some("install".to_string())),
|
install: Some(vec!["apt".to_string(), "install".to_string()]),
|
||||||
uninstall: ("apt".to_string(), Some("remove".to_string())),
|
uninstall:Some(vec!["apt".to_string(), "remove".to_string()]),
|
||||||
sup: ("apt".to_string(), Some("update".to_string())),
|
sup: Some(vec!["apt".to_string(), "update".to_string(), "upgrade".to_string()]),
|
||||||
purge: ("apt".to_string(), Some("purge".to_string())),
|
purge: Some(vec!["apt".to_string(), "purge".to_string()]),
|
||||||
upgrade: ("apt".to_string(), Some("upgrade".to_string())),
|
upgrade: Some(vec!["apt".to_string(), "upgrade".to_string()]),
|
||||||
update: ("apt".to_string(), Some("update".to_string())),
|
update: Some(vec!["apt".to_string(), "update".to_string()]),
|
||||||
cache_clear: ("apt".to_string(), Some("clean".to_string())),
|
cache_clear: Some(vec!["apt".to_string(), "clean".to_string()]),
|
||||||
complete_cache_clear: ("apt-get".to_string(), Some("autoclean".to_string())),
|
complete_cache_clear: Some(vec!["apt-get".to_string(), "autoclean".to_string()]),
|
||||||
exe: PathBuf::from("/usr/bin/apt"),
|
exe: PathBuf::from("/usr/bin/apt"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,19 +81,19 @@ impl PackageManager {
|
|||||||
pub fn xbps() -> PackageManager {
|
pub fn xbps() -> PackageManager {
|
||||||
PackageManager {
|
PackageManager {
|
||||||
name: "xbps".to_string(),
|
name: "xbps".to_string(),
|
||||||
search: ("xbps-query".to_string(), Some("-Rs".to_string())),
|
search: Some(vec!["xbps-query".to_string(), "-Rs".to_string()]),
|
||||||
install: ("xbps-install".to_string(), Some("-S".to_string())),
|
install: Some(vec!["xbps-install".to_string(), "-S".to_string()]),
|
||||||
uninstall: ("xbps-remove".to_string(), None),
|
uninstall: Some(vec!["xbps-remove".to_string()]),
|
||||||
sup: ("xbps-install".to_string(), Some("-Su".to_string())),
|
sup: Some(vec!["xbps-install".to_string(), "-Su".to_string()]),
|
||||||
purge: ("xbps-remove".to_string(), Some("-R".to_string())),
|
purge: Some(vec!["xbps-remove".to_string(), "-R".to_string()]),
|
||||||
upgrade: ("xbps-install".to_string(), Some("-Su".to_string())),
|
upgrade: Some(vec!["xbps-install".to_string(), "-Su".to_string()]),
|
||||||
update: ("xbps-install".to_string(), None),
|
update: Some(vec!["xbps-install".to_string()]),
|
||||||
cache_clear: ("xbps-remove".to_string(), Some("-0".to_string())),
|
cache_clear: Some(vec!["xbps-remove".to_string(), "-0".to_string()]),
|
||||||
complete_cache_clear: ("xbps-remove".to_string(), Some("-0".to_string())),
|
complete_cache_clear: Some(vec!["xbps-remove".to_string(), "-0".to_string()]),
|
||||||
exe: PathBuf::from("bin/xbps-install"),
|
exe: PathBuf::from("bin/xbps-install"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// allows setting the default.conf
|
// Allows setting the default.conf
|
||||||
// TODO: put default.conf somewhere it actually belongs rather than in
|
// TODO: put default.conf somewhere it actually belongs rather than in
|
||||||
// the current folder.
|
// the current folder.
|
||||||
pub fn set_default(&self) -> std::io::Result<()> {
|
pub fn set_default(&self) -> std::io::Result<()> {
|
||||||
@ -110,9 +113,11 @@ pub fn read_default() -> PackageManager {
|
|||||||
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