diff --git a/src/arguments.rs b/src/arguments.rs new file mode 100644 index 0000000..6319aeb --- /dev/null +++ b/src/arguments.rs @@ -0,0 +1,25 @@ +use std::collections::HashMap; + +pub fn get_package_install_list(args: Vec) -> HashMap{ + let op_args = args.get(2..).expect("Not enough arguments!").to_vec(); + let mut archive = false; + let mut packages: HashMap = 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 +} \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 8323034..0a4f96c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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!")); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e65108a..6ef6dfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>(); + 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" => {