diff options
author | fxqnlr <[email protected]> | 2022-11-17 21:20:09 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-17 21:20:09 +0100 |
commit | fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 (patch) | |
tree | ec7c7c80434b339f9442882f1e2dce6f60cc9edd /src/commands/modification.rs | |
parent | 5145dd23f1777180d8003e76f59af57643796516 (diff) | |
download | modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar.gz modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.zip |
added --clean for update && list downloadfolder
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 31 |
1 files changed, 9 insertions, 22 deletions
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 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | 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}; | 3 | 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}; |
4 | 4 | ||
5 | pub async fn modification(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
7 | if args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) } | 7 | match input.subcommand.ok_or("")? { |
8 | 8 | Subcmd::Add => { | |
9 | let arguments = Input::from(args.unwrap().join(" "))?; | 9 | add(config, input.args.ok_or("")?).await |
10 | |||
11 | if arguments.args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; | ||
12 | |||
13 | match arguments.command.as_str() { | ||
14 | "add" => { | ||
15 | add(config, arguments.args.unwrap()).await | ||
16 | }, | 10 | }, |
17 | "remove" => { | 11 | Subcmd::Remove => { |
18 | remove(config, arguments.args.unwrap()) | 12 | remove(config, input.args.ok_or("")?) |
19 | }, | 13 | }, |
20 | _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_SUBCOMMAND"))) | 14 | _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "SUBCOMMAND_NOT_AVAILABLE"))) |
21 | } | 15 | } |
22 | } | 16 | } |
23 | 17 | ||
@@ -29,8 +23,6 @@ async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::E | |||
29 | 23 | ||
30 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; | 24 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; |
31 | 25 | ||
32 | dbg!(&project); | ||
33 | |||
34 | if project.versions.is_empty() { panic!("This should never happen"); }; | 26 | if project.versions.is_empty() { panic!("This should never happen"); }; |
35 | 27 | ||
36 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; | 28 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; |
@@ -48,7 +40,6 @@ async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::E | |||
48 | //add to current list and mod table | 40 | //add to current list and mod table |
49 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { | 41 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { |
50 | Ok(mods) => { | 42 | Ok(mods) => { |
51 | dbg!(&mods); | ||
52 | if mods.contains(&project.id) { | 43 | if mods.contains(&project.id) { |
53 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 44 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
54 | else { | 45 | else { |
@@ -60,7 +51,6 @@ async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::E | |||
60 | 51 | ||
61 | match mods_get_all_ids(config.clone()) { | 52 | match mods_get_all_ids(config.clone()) { |
62 | Ok(mods) => { | 53 | Ok(mods) => { |
63 | dbg!(&mods); | ||
64 | if mods.contains(&project.id) { | 54 | if mods.contains(&project.id) { |
65 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) | 55 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) |
66 | } else { | 56 | } else { |
@@ -81,8 +71,5 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
81 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; | 71 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; |
82 | 72 | ||
83 | //TODO implement remove from modlist if not in any other lists && config clean is true | 73 | //TODO implement remove from modlist if not in any other lists && config clean is true |
84 | match userlist_remove(config, current_list.id, mod_id) { | 74 | userlist_remove(config, current_list.id, mod_id) |
85 | Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, | ||
86 | Ok(()) => Ok(()), | ||
87 | } | ||
88 | } | 75 | } |