Better beahvior setting default
This commit is contained in:
parent
f1ecfdd620
commit
e08320f5ea
@ -89,22 +89,23 @@ impl<'a> PackageManager<'a> {
|
|||||||
// 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 mut conf = match env::home_dir() {
|
let conf = env::home_dir().unwrap_or_else(|| {
|
||||||
Some(path) => path,
|
println!("Could not find home directory. Default cannot be saved properly!");
|
||||||
None => {
|
|
||||||
println!("Could not find home! Default cannot set properly!");
|
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
}
|
|
||||||
};
|
|
||||||
conf.push(".config/rux/");
|
|
||||||
fs::create_dir_all(&conf).unwrap_or_else(|why| {
|
|
||||||
println!("! {:?}", why.kind());
|
|
||||||
});
|
});
|
||||||
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)?;
|
let mut file = File::create(conf)?;
|
||||||
file.write_all(self.name.as_bytes())?;
|
file.write_all(self.name.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all() -> Vec<PackageManager<'a>> {
|
pub fn all() -> Vec<PackageManager<'a>> {
|
||||||
let pacmatic = PackageManager::pacmatic();
|
let pacmatic = PackageManager::pacmatic();
|
||||||
let pacman = PackageManager::pacman();
|
let pacman = PackageManager::pacman();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user