Better formatting

This commit is contained in:
Beefki 2017-11-07 21:27:32 -06:00
parent e08320f5ea
commit be33b46f1d
3 changed files with 22 additions and 31 deletions

View File

@ -42,36 +42,32 @@ impl Config {
match (prog.first(), &self.term) { match (prog.first(), &self.term) {
(None, &None) => { (None, &None) => {
let mut child = Command::new(&command).spawn().expect( let mut child = Command::new(&command).spawn().expect(
"Failed to open package manager" "Failed to open package manager",
); );
child.wait().expect("Failed to wait on package manager"); child.wait().expect("Failed to wait on package manager");
}, }
(None, &Some(ref term)) => { (None, &Some(ref term)) => {
let mut child = Command::new(&command) let mut child = Command::new(&command).arg(term).spawn().expect(
.arg(term) "Failed to open package manager",
.spawn() );
.expect("Failed to open package manager");
child.wait().expect("Failed to wait on package manager"); child.wait().expect("Failed to wait on package manager");
}, }
(Some(_), &None) => { (Some(_), &None) => {
for arg in &prog { for arg in &prog {
let mut child =Command::new(&command) let mut child = Command::new(&command).arg(arg).spawn().expect(
.arg(arg) "Failed to open package manager",
.spawn() );
.expect("Failed to open package manager");
child.wait().expect("Failed to wait on child"); child.wait().expect("Failed to wait on child");
} }
}, }
(Some(_), &Some(ref term)) => { (Some(_), &Some(ref term)) => {
for arg in &prog { for arg in &prog {
let mut child = Command::new(&command) let mut child = Command::new(&command).arg(arg).arg(term).spawn().expect(
.arg(arg) "Failed to open package manager",
.arg(term) );
.spawn()
.expect("Failed to open package manager");
child.wait().expect("Failed to wait on child"); child.wait().expect("Failed to wait on child");
} }
}, }
} }
} }
/// Creates a `Config` from passed arguments, parses the `Management` enum /// Creates a `Config` from passed arguments, parses the `Management` enum

View File

@ -23,9 +23,7 @@ fn main() {
let config = Config::new(); let config = Config::new();
//Sets a path to `~/.config/rux/` //Sets a path to `~/.config/rux/`
let mut ruxconf = std::env::home_dir().unwrap_or_else(|| { let mut ruxconf = std::env::home_dir().unwrap_or_else(|| PathBuf::new());
PathBuf::new()
});
ruxconf.push(".config/rux/rux.conf"); ruxconf.push(".config/rux/rux.conf");
// Checks if `~/.config/rux/rux.conf` exists and skips loading any // Checks if `~/.config/rux/rux.conf` exists and skips loading any
@ -34,7 +32,7 @@ fn main() {
let pac = read_default(ruxconf).unwrap_or_else(|err| { let pac = read_default(ruxconf).unwrap_or_else(|err| {
eprintln!("{:?}", err); eprintln!("{:?}", err);
std::process::exit(1) std::process::exit(1)
}); });
config.run(pac); config.run(pac);
std::process::exit(0); std::process::exit(0);
} }
@ -42,7 +40,7 @@ fn main() {
// Loads all PackageManagers into a Vec to search through // Loads all PackageManagers into a Vec to search through
let managers = PackageManager::all(); let managers = PackageManager::all();
// Iterates through the `Vec<PackageManager>` until it finds a match, // Iterates through the `Vec<PackageManager>` until it finds a match,
// asks the user if they want to use that manager, and if they want to // asks the user if they want to use that manager, and if they want to
// set it as default to ALWAYS use that manager. Finally sends all the // set it as default to ALWAYS use that manager. Finally sends all the
// needed information to run the package manager // needed information to run the package manager
@ -63,10 +61,7 @@ fn main() {
println!("Would you like to set {} as default? [y/N]", prog.name); println!("Would you like to set {} as default? [y/N]", prog.name);
if input().unwrap().trim().to_lowercase() == "y" { if input().unwrap().trim().to_lowercase() == "y" {
prog.set_default().unwrap_or_else(|err| { prog.set_default().unwrap_or_else(|err| {
println!( println!("An error occurred trying to set default {:?}", err.kind())
"An error occurred trying to set default {:?}",
err.kind()
)
}); });
} }
config.run(prog); config.run(prog);

View File

@ -12,7 +12,7 @@ pub struct PackageManager<'a> {
pub name: &'a str, pub name: &'a str,
pub search: Option<Vec<&'a str>>, pub search: Option<Vec<&'a str>>,
pub install: Option<Vec<&'a str>>, pub install: Option<Vec<&'a str>>,
pub uninstall: Option<Vec<&'a str>>, pub uninstall: Option<Vec<&'a str>>,
pub sup: Option<Vec<&'a str>>, pub sup: Option<Vec<&'a str>>,
pub purge: Option<Vec<&'a str>>, pub purge: Option<Vec<&'a str>>,
pub update: Option<Vec<&'a str>>, pub update: Option<Vec<&'a str>>,
@ -60,7 +60,7 @@ impl<'a> PackageManager<'a> {
name: "apt", name: "apt",
search: Some(vec!["apt", "search"]), search: Some(vec!["apt", "search"]),
install: Some(vec!["apt", "install"]), install: Some(vec!["apt", "install"]),
uninstall:Some(vec!["apt", "remove"]), uninstall: Some(vec!["apt", "remove"]),
sup: Some(vec!["apt", "update", "upgrade"]), sup: Some(vec!["apt", "update", "upgrade"]),
purge: Some(vec!["apt", "purge"]), purge: Some(vec!["apt", "purge"]),
upgrade: Some(vec!["apt", "upgrade"]), upgrade: Some(vec!["apt", "upgrade"]),
@ -86,7 +86,7 @@ impl<'a> PackageManager<'a> {
exe: PathBuf::from("bin/xbps-install"), exe: PathBuf::from("bin/xbps-install"),
} }
} }
// Allows setting the default `rux.conf` in folder `.config/rux/` in the // Allows setting the default `rux.conf` in folder `.config/rux/` in the
// user's home directory. Will ask once per user, including sudo. // user's home directory. Will ask once per user, including sudo.
pub fn set_default(&self) -> std::io::Result<()> { pub fn set_default(&self) -> std::io::Result<()> {
let conf = env::home_dir().unwrap_or_else(|| { let conf = env::home_dir().unwrap_or_else(|| {
@ -97,7 +97,7 @@ impl<'a> PackageManager<'a> {
let conf = conf.join(".config").join("rux"); let conf = conf.join(".config").join("rux");
fs::create_dir_all(&conf).unwrap_or_else(|err| { fs::create_dir_all(&conf).unwrap_or_else(|err| {
println!("Error setting default: {}", err); println!("Error setting default: {}", err);
return () return ();
}); });
let conf = conf.join("rux.conf"); let conf = conf.join("rux.conf");