From 93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 17 Apr 2023 20:30:16 +0200 Subject: added clap cli, modified (basically) all user interface functions; changed some functions to easier string handling --- src/commands/list.rs | 53 +++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) (limited to 'src/commands/list.rs') diff --git a/src/commands/list.rs b/src/commands/list.rs index 8e86973..80e801a 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,4 +1,4 @@ -use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, cmd_update, error::MLE}; +use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, update, error::MLE}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -8,44 +8,23 @@ pub struct List { pub download_folder: String, } -pub async fn list(config: Cfg, input: Input) -> MLE<()> { - - match input.clone().list_options.unwrap() { - ListOptions::Add => { - add(config, input) - }, - ListOptions::Change => { - change(config, input) - }, - ListOptions::Remove => { - remove(config, input) - }, - ListOptions::Version => { - version(config, input).await - } - } -} - pub fn get_current_list(config: Cfg) -> MLE { let id = config_get_current_list(config.clone())?; lists_get(config, id) } -fn add(config: Cfg, input: Input) -> MLE<()> { - let id = input.list_id.unwrap(); - let mc_version = input.list_mcversion.unwrap(); - let mod_loader = input.modloader.unwrap(); - let download_folder = input.directory.unwrap(); - lists_insert(config, id, mc_version, mod_loader, download_folder) +pub fn list_add(config: Cfg, id: String, mc_version: String, modloader: Modloader, directory: String) -> MLE<()> { + lists_insert(config, id, mc_version, modloader, directory) } -fn change(config: Cfg, input: Input) -> MLE<()> { - println!("Change default list to: {}", input.clone().list.unwrap().id); - config_change_current_list(config, input.list.unwrap().id) +pub fn list_change(config: Cfg, id: String) -> MLE<()> { + //TODO check if list exists + println!("Change default list to: {}", id); + config_change_current_list(config, id) } -fn remove(config: Cfg, input: Input) -> MLE<()> { - lists_remove(config, input.list.unwrap().id) +pub fn list_remove(config: Cfg, id: String) -> MLE<()> { + lists_remove(config, id) } ///Changing the current lists version and updating it @@ -54,14 +33,12 @@ fn remove(config: Cfg, input: Input) -> MLE<()> { /// /// * `config` - The current config /// * `args` - All args, to extract the new version -async fn version(config: Cfg, input: Input) -> MLE<()> { - println!("Change version for list {} to minecraft version: {}", input.clone().list.unwrap().id, input.clone().list_mcversion.unwrap()); +pub async fn list_version(config: Cfg, id: String, mc_version: String, download: bool, delete: bool) -> MLE<()> { + println!("Change version for list {} to minecraft version: {}", id, mc_version); - lists_version(config.clone(), input.clone().list.ok_or("").unwrap().id, input.clone().list_mcversion.ok_or("").unwrap())?; - - //Linebreak readability - println!(""); + lists_version(config.clone(), &id, &mc_version)?; - println!("Check for updates for new minecraft version in list {}", input.clone().list.unwrap().id); - cmd_update(config, vec![input.list.ok_or("").unwrap()], true, input.direct_download, input.delete_old).await + println!("\nCheck for updates for new minecraft version in list {}", id); + let list = lists_get(config.clone(), id)?; + update(config, vec![list], true, download, delete).await } -- cgit v1.2.3