working command line parser i think

mistress
Lilly Rosaline 2 years ago
parent 13b6c2d111
commit c1ccbce005

@ -0,0 +1,25 @@
use std::collections::HashMap;
pub fn get_package_install_list(args: Vec<String>) -> HashMap<String, bool>{
let op_args = args.get(2..).expect("Not enough arguments!").to_vec();
let mut archive = false;
let mut packages: HashMap<String, bool> = HashMap::new();
for arg in op_args {
match arg.as_str() {
"-r" | "--remote" => {
archive = false;
}
"-a" | "--archive"=> {
archive = true;
}
_ => {
if !arg.starts_with("-") {
packages.insert(arg, archive);
} else {
panic!("Unknown flag '{arg}'");
}
}
}
}
packages
}

@ -19,8 +19,4 @@ impl Default for Config {
}
pub(crate) fn read_config() -> Config {
toml::from_str("/cfg/gaypk/config.toml").expect("Parse failed!")
}
pub(crate) fn write_config(cfg: Config) {
let file = File::create(crate::config::read_config().installation_path + "config.toml").expect("Failed to read file");
writeln!(file, toml::to_string_pretty(&cfg).expect("Write failed!"));
}

@ -6,27 +6,21 @@ mod repository;
mod install;
mod package;
mod config;
mod arguments;
use std::collections::HashMap;
use crate::repository::find_package_in_repositories;
fn main() {
let operation = std::env::args().nth(1).expect("too few arguments!"); // Get the operation
let args = std::env::args().collect::<Vec<String>>();
let operation = args.get(1).expect("Not enough arguments!"); // Get the operation
let args = args.get(2..).unwrap().to_vec();
match operation.as_str() {
"upgrade" | "u" => { // Will upgrade the selected package(s).
let packages = arguments::get_package_install_list(args);
}
"install" | "i" => { // Install the selected package(s).
if std::env::args().nth(2).expect("too few arguments!") == "--archive" { // Indicates that the package(s) are archives instead of folders.
} else {
let package_name = std::env::args().nth(2).expect("too few arguments!"); // Get the first package name
find_package_in_repositories(&package_name, None); // Go through and find the package
println!("Reading package list");
let package_list = sled::open(crate::config::read_config().installation_path + "packages").expect("Failed to open package list");
if package_list.contains_key(&package_name).expect("Unexpected error") {
println!("Package was found in package list, checking for updates");
}
}
let packages = arguments::get_package_install_list(args);
}
"remove" | "r" => {

Loading…
Cancel
Save