91 lines
2.8 KiB
Rust
91 lines
2.8 KiB
Rust
mod packagemanager;
|
|
use packagemanager::{PackageManager, read_default};
|
|
|
|
mod management;
|
|
|
|
mod config;
|
|
use config::Config;
|
|
|
|
use std::io;
|
|
use std::path::PathBuf;
|
|
|
|
/// Takes user input. `io::Result<T>` returns either `Ok(T)`
|
|
/// or `Err(io::Error)` Error handling is common on inputs so brevity
|
|
/// is nice.
|
|
fn input() -> io::Result<String> {
|
|
let mut val = String::new();
|
|
io::stdin().read_line(&mut val)?;
|
|
Ok(val)
|
|
}
|
|
|
|
fn main() {
|
|
//pulls in the args passed and stores them in a `Config` struct
|
|
let config = Config::new();
|
|
|
|
//Sets a path to `~/.config/rux/`
|
|
let mut ruxconf = std::env::home_dir().unwrap_or_else(|| PathBuf::new());
|
|
ruxconf.push(".config/rux/rux.conf");
|
|
|
|
// Checks if `~/.config/rux/rux.conf` exists and skips loading any
|
|
// other package manager and searching for them.
|
|
if ruxconf.is_file() {
|
|
let pac = read_default(ruxconf).unwrap_or_else(|err| {
|
|
eprintln!("{:?}", err);
|
|
std::process::exit(1)
|
|
});
|
|
config.run(pac);
|
|
std::process::exit(0);
|
|
}
|
|
|
|
// Loads all PackageManagers into a Vec to search through
|
|
let managers = PackageManager::all();
|
|
|
|
// 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
|
|
// set it as default to ALWAYS use that manager. Finally sends all the
|
|
// needed information to run the package manager
|
|
let mut found: bool = false;
|
|
for prog in managers {
|
|
if found {
|
|
break;
|
|
}
|
|
if prog.exe.is_file() {
|
|
println!(
|
|
"Found {}, is this the manager you want to use? [Y/n]",
|
|
prog.name
|
|
);
|
|
if input().unwrap().trim().to_lowercase() == "n" {
|
|
continue;
|
|
} else {
|
|
found = true;
|
|
println!("Would you like to set {} as default? [y/N]", prog.name);
|
|
if input().unwrap().trim().to_lowercase() == "y" {
|
|
prog.set_default().unwrap_or_else(|err| {
|
|
println!("An error occurred trying to set default {:?}", err.kind())
|
|
});
|
|
}
|
|
config.run(prog);
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
println!("Sorry, your desired package manager is not supported at this time");
|
|
std::process::exit(0);
|
|
}
|
|
}
|
|
|
|
fn help() {
|
|
println!(
|
|
"COMMANDS:
|
|
-S Installs a new package
|
|
-Ss Searches for a package
|
|
-Sy Updates local cache from repo
|
|
-Su Upgrades with just your local cache
|
|
-Syu Upgrades the local cache and then updates the system
|
|
-R Removes a package from the system
|
|
-Rdns Purges a package from the system
|
|
-Sc Clears your local cache
|
|
-Scc Purges your local cache"
|
|
);
|
|
}
|