From fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 17 Nov 2022 21:20:09 +0100 Subject: added --clean for update && list downloadfolder --- src/commands/modification.rs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src/commands/modification.rs') diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 595b677..519a0cb 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,23 +1,17 @@ use std::io::{Error, ErrorKind}; -use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::Input, get_current_list}; +use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::{Input, Subcmd}, get_current_list}; -pub async fn modification(config: Cfg, args: Option>) -> Result<(), Box> { +pub async fn modification(config: Cfg, input: Input) -> Result<(), Box> { - if args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) } - - let arguments = Input::from(args.unwrap().join(" "))?; - - if arguments.args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; - - match arguments.command.as_str() { - "add" => { - add(config, arguments.args.unwrap()).await + match input.subcommand.ok_or("")? { + Subcmd::Add => { + add(config, input.args.ok_or("")?).await }, - "remove" => { - remove(config, arguments.args.unwrap()) + Subcmd::Remove => { + remove(config, input.args.ok_or("")?) }, - _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_SUBCOMMAND"))) + _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "SUBCOMMAND_NOT_AVAILABLE"))) } } @@ -29,8 +23,6 @@ async fn add(config: Cfg, args: Vec) -> Result<(), Box) -> Result<(), Box { - dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } else { @@ -60,7 +51,6 @@ async fn add(config: Cfg, args: Vec) -> Result<(), Box { - dbg!(&mods); if mods.contains(&project.id) { return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) } else { @@ -81,8 +71,5 @@ fn remove(config: Cfg, args: Vec) -> Result<(), Box { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, - Ok(()) => Ok(()), - } + userlist_remove(config, current_list.id, mod_id) } -- cgit v1.2.3