diff options
author | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-06 23:06:54 +0100 |
commit | ea50af892c4268ae06f6df40ee435eadd076228d (patch) | |
tree | dce2f1fed88f168552b8069d22d9176d7dd2879d /src/commands | |
parent | c33b8be79e8cfac9e2fa76c1f63c85e020cdf4a0 (diff) | |
download | modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar modlist-ea50af892c4268ae06f6df40ee435eadd076228d.tar.gz modlist-ea50af892c4268ae06f6df40ee435eadd076228d.zip |
halfswitch to rusqlite; db tests
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/list.rs | 10 | ||||
-rw-r--r-- | src/commands/modification.rs | 28 | ||||
-rw-r--r-- | src/commands/setup.rs | 6 | ||||
-rw-r--r-- | src/commands/update.rs | 4 |
4 files changed, 27 insertions, 21 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index 3dfe1ad..ffa5926 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{db::{insert_list, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; | 3 | use crate::{db::{lists_insert, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; |
4 | 4 | ||
5 | #[derive(Clone)] | 5 | #[derive(Clone)] |
6 | pub struct List { | 6 | pub struct List { |
@@ -52,8 +52,8 @@ fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> | |||
52 | "fabric" => Modloader::Fabric, | 52 | "fabric" => Modloader::Fabric, |
53 | _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) | 53 | _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) |
54 | }; | 54 | }; |
55 | match insert_list(config, id, mc_version, mod_loader) { | 55 | match lists_insert(config, id, mc_version, mod_loader) { |
56 | Err(err) => { Err(Box::new(err)) }, | 56 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, |
57 | Ok(()) => Ok(()), | 57 | Ok(()) => Ok(()), |
58 | } | 58 | } |
59 | }, | 59 | }, |
@@ -69,7 +69,7 @@ fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
69 | let list = String::from(&args[0]); | 69 | let list = String::from(&args[0]); |
70 | if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; | 70 | if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; |
71 | match change_list(config, list) { | 71 | match change_list(config, list) { |
72 | Err(err) => { Err(Box::new(err)) }, | 72 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, |
73 | Ok(()) => Ok(()), | 73 | Ok(()) => Ok(()), |
74 | } | 74 | } |
75 | }, | 75 | }, |
@@ -82,7 +82,7 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
82 | match args.len() { | 82 | match args.len() { |
83 | 1 => { | 83 | 1 => { |
84 | match remove_list(config, String::from(&args[0])) { | 84 | match remove_list(config, String::from(&args[0])) { |
85 | Err(err) => { Err(Box::new(err)) }, | 85 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, |
86 | Ok(()) => Ok(()), | 86 | Ok(()) => Ok(()), |
87 | } | 87 | } |
88 | }, | 88 | }, |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index e877a63..7836735 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,6 +1,6 @@ | |||
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::{insert_mod, remove_mod_from_list, get_mod_id, insert_mod_in_list, get_mods, get_mods_from_list}, 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, 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, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -40,31 +40,37 @@ async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::E | |||
40 | let current_version = available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap(); | 40 | let current_version = available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap(); |
41 | 41 | ||
42 | let file = current_version.files.into_iter().find(|f| f.primary).unwrap().url; | 42 | let file = current_version.files.into_iter().find(|f| f.primary).unwrap().url; |
43 | |||
44 | let mut available_versions_vec: Vec<String> = Vec::new(); | ||
45 | for ver in available_versions { | ||
46 | available_versions_vec.push(ver.id); | ||
47 | } | ||
43 | //add to current list and mod table | 48 | //add to current list and mod table |
44 | match get_mods_from_list(config.clone(), current_list.clone()) { | 49 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { |
45 | Ok(mods) => { | 50 | Ok(mods) => { |
46 | dbg!(&mods); | 51 | dbg!(&mods); |
47 | if mods.contains(&project.id) { | 52 | if mods.contains(&project.id) { |
48 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 53 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
49 | else { | 54 | else { |
50 | insert_mod_in_list(config.clone(), current_list.clone(), String::from(&project.id), current_version.id, available_versions, file)?; | 55 | userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?; |
51 | } | 56 | } |
52 | }, | 57 | }, |
53 | Err(..) => insert_mod_in_list(config.clone(), current_list, String::from(&project.id), current_version.id, available_versions, file)?, | 58 | Err(..) => userlist_insert(config.clone(), current_list.id, String::from(&project.id), current_version.id, available_versions_vec, file)?, |
54 | }; | 59 | }; |
55 | 60 | ||
56 | match get_mods(config.clone()) { | 61 | match mods_get_all_ids(config.clone()) { |
57 | Ok(mods) => { | 62 | Ok(mods) => { |
58 | dbg!(&mods); | 63 | dbg!(&mods); |
59 | if mods.contains(&project.id) { | 64 | if mods.contains(&project.id) { |
60 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) | 65 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_IN_DATABASE"))) |
61 | } else { | 66 | } else { |
62 | insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | 67 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; |
63 | } | 68 | } |
64 | }, | 69 | }, |
65 | Err(..) => insert_mod(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?, | 70 | Err(..) => { |
71 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | ||
72 | }, | ||
66 | }; | 73 | }; |
67 | |||
68 | Ok(()) | 74 | Ok(()) |
69 | } | 75 | } |
70 | 76 | ||
@@ -72,11 +78,11 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
72 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; | 78 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; |
73 | 79 | ||
74 | let current_list = get_current_list(config.clone())?; | 80 | let current_list = get_current_list(config.clone())?; |
75 | let mod_id = get_mod_id(config.clone(), String::from(&args[0]))?; | 81 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; |
76 | 82 | ||
77 | //TODO implement remove from modlist if not in any other lists && config clean is true | 83 | //TODO implement remove from modlist if not in any other lists && config clean is true |
78 | match remove_mod_from_list(config, current_list, mod_id) { | 84 | match userlist_remove(config, current_list.id, mod_id) { |
79 | Err(err) => { Err(Box::new(err)) }, | 85 | Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, |
80 | Ok(()) => Ok(()), | 86 | Ok(()) => Ok(()), |
81 | } | 87 | } |
82 | } | 88 | } |
diff --git a/src/commands/setup.rs b/src/commands/setup.rs index 0223a21..0940959 100644 --- a/src/commands/setup.rs +++ b/src/commands/setup.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::{fs::File, path::Path, io::{Error, ErrorKind}}; | 1 | use std::{fs::File, path::Path, io::{Error, ErrorKind}}; |
2 | 2 | ||
3 | use crate::{config::Cfg, db::{db_setup, get_dbversion, create_dbversion, insert_column, get_lists, get_list, get_current_versions, insert_dl_link}, modrinth::get_raw_versions}; | 3 | use crate::{config::Cfg, db::{db_setup, user_dbversion, create_dbversion, insert_column, get_lists, get_list, get_current_versions, insert_dl_link}, modrinth::get_raw_versions}; |
4 | 4 | ||
5 | pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -10,7 +10,7 @@ pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
10 | return create(config, db_file); | 10 | return create(config, db_file); |
11 | } | 11 | } |
12 | 12 | ||
13 | match get_dbversion(config.clone()) { | 13 | match user_dbversion(config.clone()) { |
14 | Ok(ver) => { | 14 | Ok(ver) => { |
15 | match ver.as_str() { | 15 | match ver.as_str() { |
16 | _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) | 16 | _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) |
@@ -33,7 +33,7 @@ async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
33 | 33 | ||
34 | for list in lists { | 34 | for list in lists { |
35 | println!("Updating {}", list); | 35 | println!("Updating {}", list); |
36 | insert_column(config.clone(), String::from(&list), String::from("current_download"), sqlite::Type::String)?; | 36 | insert_column(config.clone(), String::from(&list), String::from("current_download"), String::new())?; |
37 | 37 | ||
38 | let full_list = get_list(config.clone(), String::from(&list))?; | 38 | let full_list = get_list(config.clone(), String::from(&list))?; |
39 | 39 | ||
diff --git a/src/commands/update.rs b/src/commands/update.rs index 284d289..d278a78 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -4,13 +4,13 @@ use reqwest::Client; | |||
4 | 4 | ||
5 | use futures_util::StreamExt; | 5 | use futures_util::StreamExt; |
6 | 6 | ||
7 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{get_mods_from_list, get_versions, get_list_version, change_list_versions}, List}; | 7 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, get_versions, get_list_version, change_list_versions}, List}; |
8 | 8 | ||
9 | pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 9 | pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { |
10 | 10 | ||
11 | let current_list = get_current_list(config.clone())?; | 11 | let current_list = get_current_list(config.clone())?; |
12 | 12 | ||
13 | let mods = get_mods_from_list(config.clone(), current_list.clone())?; | 13 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; |
14 | 14 | ||
15 | let mut versions = get_versions(config.clone(), mods.clone())?; | 15 | let mut versions = get_versions(config.clone(), mods.clone())?; |
16 | versions.sort_by_key(|ver| ver.mod_id.clone()); | 16 | versions.sort_by_key(|ver| ver.mod_id.clone()); |