Better beahvior setting default

This commit is contained in:
Beefki 2017-11-07 21:07:22 -06:00
parent 9892fefd2f
commit 9542d122b5

View File

@ -89,22 +89,23 @@ impl<'a> PackageManager<'a> {
// Allows setting the default `rux.conf` in folder `.config/rux/` in the
// user's home directory. Will ask once per user, including sudo.
pub fn set_default(&self) -> std::io::Result<()> {
let mut conf = match env::home_dir() {
Some(path) => path,
None => {
println!("Could not find home! Default cannot set properly!");
std::process::exit(1)
}
};
conf.push(".config/rux/");
fs::create_dir_all(&conf).unwrap_or_else(|why| {
println!("! {:?}", why.kind());
let conf = env::home_dir().unwrap_or_else(|| {
println!("Could not find home directory. Default cannot be saved properly!");
std::process::exit(1)
});
conf.push("rux.conf");
let conf = conf.join(".config").join("rux");
fs::create_dir_all(&conf).unwrap_or_else(|err| {
println!("Error setting default: {}", err);
return ()
});
let conf = conf.join("rux.conf");
let mut file = File::create(conf)?;
file.write_all(self.name.as_bytes())?;
Ok(())
}
pub fn all() -> Vec<PackageManager<'a>> {
let pacmatic = PackageManager::pacmatic();
let pacman = PackageManager::pacman();