From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/commands/list.rs | 73 +++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) (limited to 'src/commands/list.rs') diff --git a/src/commands/list.rs b/src/commands/list.rs index 2fec1c7..bc58787 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,6 +1,4 @@ -use std::io::{Error, ErrorKind}; - -use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::{MLE, ErrorType, MLError}, /*modrinth::MCVersionType*/}; +use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::MLE, /*modrinth::MCVersionType*/}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -9,78 +7,49 @@ pub struct List { pub modloader: Modloader, pub download_folder: String, } -/* -pub async fn list(config: Cfg, input: Input) -> Result<(), Box> { - match input.list_options.ok_or("")? { +pub async fn list(config: Cfg, input: Input) -> MLE<()> { + + match input.clone().list_options.unwrap() { ListOptions::Add => { - match add(config, input.args.ok_or("")?) { - Ok(..) => Ok(()), - Err(e) => Err(Box::new(e)) - } + add(config, input) }, ListOptions::Change => { - change(config, input.args) + change(config, input) }, ListOptions::Remove => { - match remove(config, input.args.ok_or("")?) { - Ok(..) => Ok(()), - Err(e) => Err(Box::new(e)) - } + remove(config, input) }, + /* Subcmd::Version => { match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await { Ok(..) => Ok(()), Err(e) => Err(Box::new(e)) } - } - _ => { - Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) - } + }*/ } } -*/ + pub fn get_current_list(config: Cfg) -> MLE { let id = config_get_current_list(config.clone())?; lists_get(config, id) } -fn add(config: Cfg, args: Vec) -> MLE<()> { - match args.len() { - 1 | 2 | 3 => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_FEW_ARGUMENTS")), - 4 => { - let id = String::from(&args[0]); - let mc_version = String::from(&args[1]); - let mod_loader = Modloader::from(&args[2])?; - let download_folder = String::from(&args[3]); - lists_insert(config, id, mc_version, mod_loader, download_folder) - }, - 5.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), - _ => panic!("list arguments should never be zero or lower"), - } +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) } -fn change(config: Cfg, args: Option>) -> Result<(), Box> { - let lists = lists_get_all_ids(config.clone())?; - if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) }; - let argsvec = args.ok_or("BAH")?; - match argsvec.len() { - 1 => { - let list = String::from(&argsvec[0]); - if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; - config_change_current_list(config, list) - }, - 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), - _ => panic!("list arguments should never lower than zero"), - } +fn change(config: Cfg, input: Input) -> MLE<()> { + //TODO reimplement current list + config_change_current_list(config, input.list.unwrap().id) } -fn remove(config: Cfg, args: Vec) -> MLE<()> { - match args.len() { - 1 => lists_remove(config, String::from(&args[0])), - 2.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), - _ => panic!("list arguments should never be zero or lower"), - } +fn remove(config: Cfg, input: Input) -> MLE<()> { + lists_remove(config, input.list.unwrap().id) } /* -- cgit v1.2.3