diff --git a/src/main.rs b/src/main.rs index d09890f..11ab307 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,8 +26,8 @@ fn main() { ruxconf.push(".config/rux/rux.conf"); if ruxconf.is_file() { - let pac = read_default().unwrap_or_else(|err| { - println!("{:?}", err); + let pac = read_default(ruxconf).unwrap_or_else(|err| { + eprintln!("{:?}", err); std::process::exit(1) }); config.run(pac); diff --git a/src/packagemanager.rs b/src/packagemanager.rs index 3b160fc..8483de9 100644 --- a/src/packagemanager.rs +++ b/src/packagemanager.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use std::io::BufReader; use std::io::prelude::*; use std::fs::{self, File}; @@ -33,7 +33,6 @@ impl<'a> PackageManager<'a> { install: Some(vec!["pacmatic", "-S"]), uninstall: Some(vec!["pacmatic", "-R"]), sup: Some(vec!["pacmatic", "-Syu"]), - //sup: Some(vec!["pacmatic", "-Sy", "-Su"]), purge: Some(vec!["pacmatic", "-Rdns"]), upgrade: Some(vec!["pacmatic", "-Su"]), update: Some(vec!["pacmatic", "-Sy"]), @@ -89,9 +88,7 @@ impl<'a> PackageManager<'a> { exe: PathBuf::from("bin/xbps-install"), } } - // Allows setting the default.conf - // TODO: put default.conf somewhere it actually belongs rather than in - // the current folder. + // Allows setting the default in rux.conf pub fn set_default(&self) -> std::io::Result<()> { let mut home = match env::home_dir() { Some(path) => path, @@ -104,7 +101,6 @@ impl<'a> PackageManager<'a> { fs::create_dir_all(&home).unwrap_or_else(|why| { println!("! {:?}", why.kind()); }); - println!("{:?}", &home.display()); home.push("rux.conf"); let mut file = File::create(home)?; file.write_all(self.name.as_bytes())?; @@ -124,14 +120,15 @@ impl<'a> PackageManager<'a> { /// 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 /// issue before exiting. -// TODO: Have this delete malformed default.conf -pub fn read_default<'a>() -> Result, Box> { +pub fn read_default<'a, P: AsRef>(ruxconf: P) -> Result, Box> { + /* let mut home = env::home_dir().unwrap_or_else(|| { eprintln!("Cannot load file, home directory cannot be found"); std::process::exit(1) }); home.push(".config/rux/rux.conf"); - let file = File::open(&home)?; + */ + let file = File::open(&ruxconf)?; let buffered = BufReader::new(file); for line in buffered.lines() { match &*line.unwrap() { @@ -140,9 +137,9 @@ pub fn read_default<'a>() -> Result, Box> { "apt" => return Ok(PackageManager::apt()), "xbps" => return Ok(PackageManager::xbps()), _ => { - println!("Default either not set or has been changed"); - std::fs::remove_file(home).unwrap_or_else(|err| { - println!("Failed to delete: {:?}", err); + eprintln!("Default either not set or has been changed"); + std::fs::remove_file(ruxconf).unwrap_or_else(|err| { + eprintln!("Failed to delete: {:?}", err); }); std::process::exit(1) }