diff options
-rw-r--r-- | src/apis/modrinth.rs | 2 | ||||
-rw-r--r-- | src/commands.rs | 5 | ||||
-rw-r--r-- | src/commands/download.rs | 2 | ||||
-rw-r--r-- | src/commands/io.rs | 7 | ||||
-rw-r--r-- | src/commands/list.rs | 193 | ||||
-rw-r--r-- | src/commands/mod.rs | 11 | ||||
-rw-r--r-- | src/commands/modification.rs | 35 | ||||
-rw-r--r-- | src/commands/update.rs | 11 | ||||
-rw-r--r-- | src/config.rs | 5 | ||||
-rw-r--r-- | src/data.rs | 13 | ||||
-rw-r--r-- | src/data/gameversion.rs (renamed from src/lib.rs) | 54 | ||||
-rw-r--r-- | src/data/list.rs | 19 | ||||
-rw-r--r-- | src/data/modification.rs | 11 | ||||
-rw-r--r-- | src/data/modloader.rs | 39 | ||||
-rw-r--r-- | src/data/project.rs | 12 | ||||
-rw-r--r-- | src/db.rs | 2 | ||||
-rw-r--r-- | src/files.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 34 |
18 files changed, 220 insertions, 242 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 7cdc719..7f1fb52 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -139,7 +139,7 @@ async fn get( | |||
139 | 139 | ||
140 | let client = Client::builder() | 140 | let client = Client::builder() |
141 | .user_agent(format!( | 141 | .user_agent(format!( |
142 | "fxqnlr/modlistcli/{} ([email protected])", | 142 | "fxqnlr/modlist/{} ([email protected])", |
143 | env!("CARGO_PKG_VERSION") | 143 | env!("CARGO_PKG_VERSION") |
144 | )) | 144 | )) |
145 | .build()?; | 145 | .build()?; |
diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..a9d2c2c --- /dev/null +++ b/src/commands.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | pub mod download; | ||
2 | pub mod io; | ||
3 | pub mod list; | ||
4 | pub mod modification; | ||
5 | pub mod update; | ||
diff --git a/src/commands/download.rs b/src/commands/download.rs index 7ea5c29..269d5d3 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | 1 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
2 | 2 | ||
3 | use crate::apis::modrinth::get_raw_versions; | ||
3 | use crate::{config::Cfg, List}; | 4 | use crate::{config::Cfg, List}; |
4 | use crate::{ | 5 | use crate::{ |
5 | db::userlist_get_all_current_versions_with_mods, | 6 | db::userlist_get_all_current_versions_with_mods, |
@@ -8,7 +9,6 @@ use crate::{ | |||
8 | clean_list_dir, delete_version, disable_version, download_versions, | 9 | clean_list_dir, delete_version, disable_version, download_versions, |
9 | get_downloaded_versions, | 10 | get_downloaded_versions, |
10 | }, | 11 | }, |
11 | modrinth::get_raw_versions, | ||
12 | }; | 12 | }; |
13 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; | 13 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; |
14 | 14 | ||
diff --git a/src/commands/io.rs b/src/commands/io.rs index 3e171f1..dea0d84 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -4,13 +4,10 @@ use std::fs::File; | |||
4 | use std::io::prelude::*; | 4 | use std::io::prelude::*; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | config::Cfg, | 7 | config::Cfg, data::modification::{AddMod, IDSelector}, db::{ |
8 | db::{ | ||
9 | lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids, | 8 | lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids, |
10 | userlist_get_current_version, userlist_get_set_version, | 9 | userlist_get_current_version, userlist_get_set_version, |
11 | }, | 10 | }, error::{EType, MLErr, MLE}, mod_add, List, Modloader, STYLE_OPERATION |
12 | error::{EType, MLErr, MLE}, | ||
13 | mod_add, AddMod, IDSelector, List, Modloader, STYLE_OPERATION, | ||
14 | }; | 11 | }; |
15 | 12 | ||
16 | #[derive(Debug, Serialize, Deserialize)] | 13 | #[derive(Debug, Serialize, Deserialize)] |
diff --git a/src/commands/list.rs b/src/commands/list.rs index 148bd16..23a9f0f 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,124 +1,105 @@ | |||
1 | use indicatif::{ProgressBar, ProgressStyle}; | 1 | use indicatif::{ProgressBar, ProgressStyle}; |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | config::Cfg, | 4 | config::Cfg, data::modloader::Modloader, db::{ |
5 | db::{ | 5 | config_change_current_list, lists_get, |
6 | config_change_current_list, config_get_current_list, lists_get, | ||
7 | lists_get_all_ids, lists_insert, lists_remove, lists_version, | 6 | lists_get_all_ids, lists_insert, lists_remove, lists_version, |
8 | }, | 7 | }, error::{EType, MLErr, MLE}, update, STYLE_OPERATION |
9 | error::{EType, MLErr, MLE}, | ||
10 | update, Modloader, STYLE_OPERATION, | ||
11 | }; | 8 | }; |
12 | 9 | ||
13 | #[derive(Debug, Clone, PartialEq, Eq)] | 10 | /// # Errors |
14 | pub struct List { | 11 | pub fn add( |
15 | pub id: String, | 12 | config: &Cfg, |
16 | pub mc_version: String, | 13 | id: &str, |
17 | pub modloader: Modloader, | 14 | mc_version: &str, |
18 | pub download_folder: String, | 15 | modloader: &Modloader, |
16 | directory: &str, | ||
17 | ) -> MLE<()> { | ||
18 | let p = ProgressBar::new_spinner(); | ||
19 | p.set_style( | ||
20 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | ||
21 | MLErr::new(EType::LibIndicatif, "template error") | ||
22 | })?, | ||
23 | ); | ||
24 | p.set_message(format!("Create {id}")); | ||
25 | lists_insert(config, id, mc_version, modloader, directory)?; | ||
26 | p.finish_with_message(format!("Created {id}")); | ||
27 | Ok(()) | ||
19 | } | 28 | } |
20 | 29 | ||
21 | impl List { | 30 | /// # Errors |
22 | /// # Errors | 31 | pub fn change(config: &Cfg, id: &str) -> MLE<()> { |
23 | pub fn get_current_list(config: &Cfg) -> MLE<List> { | 32 | let p = ProgressBar::new_spinner(); |
24 | let id = config_get_current_list(config)?; | 33 | p.set_style( |
25 | lists_get(config, &id) | 34 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
26 | } | 35 | MLErr::new(EType::LibIndicatif, "template error") |
27 | 36 | })?, | |
28 | /// # Errors | 37 | ); |
29 | pub fn add( | 38 | p.set_message(format!("Change default list to {id}")); |
30 | config: &Cfg, | ||
31 | id: &str, | ||
32 | mc_version: &str, | ||
33 | modloader: &Modloader, | ||
34 | directory: &str, | ||
35 | ) -> MLE<()> { | ||
36 | let p = ProgressBar::new_spinner(); | ||
37 | p.set_style( | ||
38 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | ||
39 | MLErr::new(EType::LibIndicatif, "template error") | ||
40 | })?, | ||
41 | ); | ||
42 | p.set_message(format!("Create {id}")); | ||
43 | lists_insert(config, id, mc_version, modloader, directory)?; | ||
44 | p.finish_with_message(format!("Created {id}")); | ||
45 | Ok(()) | ||
46 | } | ||
47 | 39 | ||
48 | /// # Errors | 40 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { |
49 | pub fn change(config: &Cfg, id: &str) -> MLE<()> { | 41 | return Err(MLErr::new(EType::ArgumentError, "List not found")); |
50 | let p = ProgressBar::new_spinner(); | 42 | }; |
51 | p.set_style( | 43 | config_change_current_list(config, id)?; |
52 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | ||
53 | MLErr::new(EType::LibIndicatif, "template error") | ||
54 | })?, | ||
55 | ); | ||
56 | p.set_message(format!("Change default list to {id}")); | ||
57 | 44 | ||
58 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { | 45 | p.finish_with_message(format!("Changed default list to {id}")); |
59 | return Err(MLErr::new(EType::ArgumentError, "List not found")); | 46 | Ok(()) |
60 | }; | 47 | } |
61 | config_change_current_list(config, id)?; | ||
62 | |||
63 | p.finish_with_message(format!("Changed default list to {id}")); | ||
64 | Ok(()) | ||
65 | } | ||
66 | 48 | ||
67 | /// # Errors | 49 | /// # Errors |
68 | pub fn remove(config: &Cfg, id: &str) -> MLE<()> { | 50 | pub fn remove(config: &Cfg, id: &str) -> MLE<()> { |
69 | let p = ProgressBar::new_spinner(); | 51 | let p = ProgressBar::new_spinner(); |
70 | p.set_style( | 52 | p.set_style( |
71 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | 53 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
72 | MLErr::new(EType::LibIndicatif, "template error") | 54 | MLErr::new(EType::LibIndicatif, "template error") |
73 | })?, | 55 | })?, |
74 | ); | 56 | ); |
75 | p.set_message(format!("Remove {id}")); | 57 | p.set_message(format!("Remove {id}")); |
76 | lists_remove(config, id)?; | 58 | lists_remove(config, id)?; |
77 | p.finish_with_message(format!("Removed {id}")); | 59 | p.finish_with_message(format!("Removed {id}")); |
78 | Ok(()) | 60 | Ok(()) |
79 | } | 61 | } |
80 | 62 | ||
81 | ///Changing the current lists version and updating it | 63 | ///Changing the current lists version and updating it |
82 | /// | 64 | /// |
83 | /// #Arguments | 65 | /// #Arguments |
84 | /// | 66 | /// |
85 | /// * `config` - The current config | 67 | /// * `config` - The current config |
86 | /// * `args` - All args, to extract the new version | 68 | /// * `args` - All args, to extract the new version |
87 | /// # Errors | 69 | /// # Errors |
88 | pub async fn version( | 70 | pub async fn version( |
89 | config: &Cfg, | 71 | config: &Cfg, |
90 | id: &str, | 72 | id: &str, |
91 | mc_version: String, | 73 | mc_version: String, |
92 | download: bool, | 74 | download: bool, |
93 | delete: bool, | 75 | delete: bool, |
94 | ) -> MLE<()> { | 76 | ) -> MLE<()> { |
95 | let p = ProgressBar::new_spinner(); | 77 | let p = ProgressBar::new_spinner(); |
96 | p.set_style( | 78 | p.set_style( |
97 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | 79 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
98 | MLErr::new(EType::LibIndicatif, "template error") | 80 | MLErr::new(EType::LibIndicatif, "template error") |
99 | })?, | 81 | })?, |
100 | ); | 82 | ); |
101 | p.set_message(format!( | 83 | p.set_message(format!( |
102 | "Change version for list {id} to minecraft version: {mc_version}" | 84 | "Change version for list {id} to minecraft version: {mc_version}" |
103 | )); | 85 | )); |
104 | 86 | ||
105 | lists_version(config, id, &mc_version)?; | 87 | lists_version(config, id, &mc_version)?; |
106 | 88 | ||
107 | p.finish_with_message(format!( | 89 | p.finish_with_message(format!( |
108 | "Changed version for list {id} to minecraft version: {mc_version}" | 90 | "Changed version for list {id} to minecraft version: {mc_version}" |
109 | )); | 91 | )); |
110 | 92 | ||
111 | let list = lists_get(config, id)?; | 93 | let list = lists_get(config, id)?; |
112 | update(config, vec![list], true, download, delete).await | 94 | update(config, vec![list], true, download, delete).await |
113 | } | 95 | } |
114 | 96 | ||
115 | /// # Errors | 97 | /// # Errors |
116 | pub fn list(config: &Cfg) -> MLE<()> { | 98 | pub fn list(config: &Cfg) -> MLE<()> { |
117 | let lists = lists_get_all_ids(config)?; | 99 | let lists = lists_get_all_ids(config)?; |
118 | for list in lists { | 100 | for list in lists { |
119 | let l = lists_get(config, &list)?; | 101 | let l = lists_get(config, &list)?; |
120 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); | 102 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); |
121 | } | ||
122 | Ok(()) | ||
123 | } | 103 | } |
104 | Ok(()) | ||
124 | } | 105 | } |
diff --git a/src/commands/mod.rs b/src/commands/mod.rs deleted file mode 100644 index 0f13056..0000000 --- a/src/commands/mod.rs +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | pub mod download; | ||
2 | pub mod io; | ||
3 | pub mod list; | ||
4 | pub mod modification; | ||
5 | pub mod update; | ||
6 | |||
7 | pub use download::*; | ||
8 | pub use io::*; | ||
9 | pub use list::*; | ||
10 | pub use modification::*; | ||
11 | pub use update::*; | ||
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 8f115ee..d20f575 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -3,44 +3,13 @@ use std::collections::HashMap; | |||
3 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | 3 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | config::Cfg, | 6 | apis::modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, config::Cfg, data::{modification::{AddMod, IDSelector}, project::ProjectInfo}, db::{ |
7 | db::{ | ||
8 | lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, | 7 | lists_get_all_ids, mods_get_id, mods_get_info, mods_insert, |
9 | mods_remove, userlist_get_all_ids, userlist_get_current_version, | 8 | mods_remove, userlist_get_all_ids, userlist_get_current_version, |
10 | userlist_insert, userlist_remove, | 9 | userlist_insert, userlist_remove, |
11 | }, | 10 | }, error::{EType, MLErr, MLE}, files::{delete_version, download_versions}, List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION |
12 | error::{EType, MLErr, MLE}, | ||
13 | files::{delete_version, download_versions}, | ||
14 | modrinth::{ | ||
15 | extract_current_version, get_raw_versions, project, projects, versions, | ||
16 | Version, | ||
17 | }, | ||
18 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, | ||
19 | }; | 11 | }; |
20 | 12 | ||
21 | #[derive(Debug)] | ||
22 | pub struct AddMod { | ||
23 | pub id: IDSelector, | ||
24 | pub set_version: bool, | ||
25 | } | ||
26 | |||
27 | #[derive(Debug, PartialEq, Eq)] | ||
28 | pub enum IDSelector { | ||
29 | ModificationID(String), | ||
30 | VersionID(String), | ||
31 | } | ||
32 | |||
33 | #[derive(Debug, Clone)] | ||
34 | pub struct ProjectInfo { | ||
35 | pub mod_id: String, | ||
36 | pub slug: String, | ||
37 | pub title: String, | ||
38 | pub current_version: Option<Version>, | ||
39 | pub applicable_versions: Vec<String>, | ||
40 | pub download_link: String, | ||
41 | pub set_version: bool, | ||
42 | } | ||
43 | |||
44 | /// # Errors | 13 | /// # Errors |
45 | pub async fn mod_add( | 14 | pub async fn mod_add( |
46 | config: &Cfg, | 15 | config: &Cfg, |
diff --git a/src/commands/update.rs b/src/commands/update.rs index f83030d..721ced5 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,18 +1,13 @@ | |||
1 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | 1 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
2 | 2 | ||
3 | use crate::{ | 3 | use crate::{ |
4 | config::Cfg, | 4 | apis::modrinth::{extract_current_version, versions, Version}, config::Cfg, data::list::List, db::{ |
5 | db::{ | ||
6 | mods_get_info, userlist_change_versions, userlist_get_all_ids, | 5 | mods_get_info, userlist_change_versions, userlist_get_all_ids, |
7 | userlist_get_applicable_versions, userlist_get_current_version, | 6 | userlist_get_applicable_versions, userlist_get_current_version, |
8 | userlist_get_set_version, | 7 | userlist_get_set_version, |
9 | }, | 8 | }, error::{EType, MLErr, MLE}, files::{ |
10 | error::{EType, MLErr, MLE}, | ||
11 | files::{ | ||
12 | clean_list_dir, delete_version, disable_version, download_versions, | 9 | clean_list_dir, delete_version, disable_version, download_versions, |
13 | }, | 10 | }, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION |
14 | modrinth::{extract_current_version, versions, Version}, | ||
15 | List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, | ||
16 | }; | 11 | }; |
17 | 12 | ||
18 | /// # Errors | 13 | /// # Errors |
diff --git a/src/config.rs b/src/config.rs index 8ecdc69..8312d15 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -7,10 +7,7 @@ use std::{ | |||
7 | use serde::{Deserialize, Serialize}; | 7 | use serde::{Deserialize, Serialize}; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | check_game_versions, | 10 | data::{gameversion::{check_game_versions, VersionLevel}, modloader::Modloader}, db::setup, error::{EType, MLErr, MLE} |
11 | db::setup, | ||
12 | error::{EType, MLErr, MLE}, | ||
13 | Modloader, VersionLevel, | ||
14 | }; | 11 | }; |
15 | 12 | ||
16 | #[derive(Debug, Clone, Serialize, Deserialize)] | 13 | #[derive(Debug, Clone, Serialize, Deserialize)] |
diff --git a/src/data.rs b/src/data.rs new file mode 100644 index 0000000..cff0f47 --- /dev/null +++ b/src/data.rs | |||
@@ -0,0 +1,13 @@ | |||
1 | pub mod list; | ||
2 | pub mod gameversion; | ||
3 | pub mod modloader; | ||
4 | pub mod project; | ||
5 | pub mod modification; | ||
6 | |||
7 | pub static STYLE_BAR_BYTE: &str = | ||
8 | "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | ||
9 | pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; | ||
10 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; | ||
11 | pub static STYLE_OPERATION: &str = " {wide_msg}"; | ||
12 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; | ||
13 | pub static PROGRESS_CHARS: &str = "#>-"; | ||
diff --git a/src/lib.rs b/src/data/gameversion.rs index be63ff8..3868502 100644 --- a/src/lib.rs +++ b/src/data/gameversion.rs | |||
@@ -1,66 +1,15 @@ | |||
1 | pub mod apis; | ||
2 | pub mod cache; | ||
3 | pub mod commands; | ||
4 | pub mod config; | ||
5 | pub mod db; | ||
6 | pub mod error; | ||
7 | pub mod files; | ||
8 | |||
9 | use std::{ | 1 | use std::{ |
10 | fmt::Display, | ||
11 | fs::{self, remove_file, File}, | 2 | fs::{self, remove_file, File}, |
12 | io::{Read, Write}, | 3 | io::{Read, Write}, |
13 | time::Duration, | 4 | time::Duration, |
14 | }; | 5 | }; |
15 | 6 | ||
16 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; | 7 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; |
17 | pub use apis::*; | ||
18 | pub use commands::*; | ||
19 | use error::{EType, MLErr, MLE}; | 8 | use error::{EType, MLErr, MLE}; |
20 | use indicatif::{ProgressBar, ProgressStyle}; | 9 | use indicatif::{ProgressBar, ProgressStyle}; |
21 | use serde::{Deserialize, Serialize}; | 10 | use serde::{Deserialize, Serialize}; |
22 | 11 | ||
23 | pub static STYLE_BAR_BYTE: &str = | 12 | use crate::{apis, error, STYLE_MESSAGE}; |
24 | "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | ||
25 | pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; | ||
26 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; | ||
27 | pub static STYLE_OPERATION: &str = " {wide_msg}"; | ||
28 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; | ||
29 | pub static PROGRESS_CHARS: &str = "#>-"; | ||
30 | |||
31 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
32 | pub enum Modloader { | ||
33 | #[serde(rename(serialize = "fabric", deserialize = "fabric"))] | ||
34 | Fabric, | ||
35 | #[serde(rename(serialize = "forge", deserialize = "forge"))] | ||
36 | Forge, | ||
37 | #[serde(rename(serialize = "quilt", deserialize = "quilt"))] | ||
38 | Quilt, | ||
39 | } | ||
40 | |||
41 | impl Modloader { | ||
42 | /// # Errors | ||
43 | pub fn from(string: &str) -> MLE<Modloader> { | ||
44 | match string { | ||
45 | "forge" => Ok(Modloader::Forge), | ||
46 | "fabric" => Ok(Modloader::Fabric), | ||
47 | "quilt" => Ok(Modloader::Quilt), | ||
48 | _ => { | ||
49 | Err(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER")) | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | impl Display for Modloader { | ||
56 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
57 | match self { | ||
58 | Modloader::Fabric => write!(f, "fabric"), | ||
59 | Modloader::Forge => write!(f, "forge"), | ||
60 | Modloader::Quilt => write!(f, "quilt"), | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | 13 | ||
65 | #[derive(Debug, Clone, Deserialize, Serialize)] | 14 | #[derive(Debug, Clone, Deserialize, Serialize)] |
66 | pub enum VersionLevel { | 15 | pub enum VersionLevel { |
@@ -108,7 +57,6 @@ pub fn load_game_versions(path: &str) -> MLE<Vec<GameVersion>> { | |||
108 | } | 57 | } |
109 | 58 | ||
110 | impl VersionLevel { | 59 | impl VersionLevel { |
111 | #[must_use] | ||
112 | pub fn from(str: &str) -> Self { | 60 | pub fn from(str: &str) -> Self { |
113 | match str { | 61 | match str { |
114 | "release" => VersionLevel::Release, | 62 | "release" => VersionLevel::Release, |
diff --git a/src/data/list.rs b/src/data/list.rs new file mode 100644 index 0000000..0045b7a --- /dev/null +++ b/src/data/list.rs | |||
@@ -0,0 +1,19 @@ | |||
1 | use crate::{config::Cfg, db::{config_get_current_list, lists_get}, error::MLE}; | ||
2 | |||
3 | use super::modloader::Modloader; | ||
4 | |||
5 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
6 | pub struct List { | ||
7 | pub id: String, | ||
8 | pub mc_version: String, | ||
9 | pub modloader: Modloader, | ||
10 | pub download_folder: String, | ||
11 | } | ||
12 | |||
13 | impl List { | ||
14 | /// # Errors | ||
15 | pub fn get_current_list(config: &Cfg) -> MLE<List> { | ||
16 | let id = config_get_current_list(config)?; | ||
17 | lists_get(config, &id) | ||
18 | } | ||
19 | } | ||
diff --git a/src/data/modification.rs b/src/data/modification.rs new file mode 100644 index 0000000..84047ff --- /dev/null +++ b/src/data/modification.rs | |||
@@ -0,0 +1,11 @@ | |||
1 | #[derive(Debug)] | ||
2 | pub struct AddMod { | ||
3 | pub id: IDSelector, | ||
4 | pub set_version: bool, | ||
5 | } | ||
6 | |||
7 | #[derive(Debug, PartialEq, Eq)] | ||
8 | pub enum IDSelector { | ||
9 | ModificationID(String), | ||
10 | VersionID(String), | ||
11 | } | ||
diff --git a/src/data/modloader.rs b/src/data/modloader.rs new file mode 100644 index 0000000..050213f --- /dev/null +++ b/src/data/modloader.rs | |||
@@ -0,0 +1,39 @@ | |||
1 | use std::fmt::Display; | ||
2 | |||
3 | use serde::{Deserialize, Serialize}; | ||
4 | |||
5 | use crate::error::{EType, MLErr, MLE}; | ||
6 | |||
7 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | ||
8 | pub enum Modloader { | ||
9 | #[serde(rename(serialize = "fabric", deserialize = "fabric"))] | ||
10 | Fabric, | ||
11 | #[serde(rename(serialize = "forge", deserialize = "forge"))] | ||
12 | Forge, | ||
13 | #[serde(rename(serialize = "quilt", deserialize = "quilt"))] | ||
14 | Quilt, | ||
15 | } | ||
16 | |||
17 | impl Modloader { | ||
18 | /// # Errors | ||
19 | pub fn from(string: &str) -> MLE<Modloader> { | ||
20 | match string { | ||
21 | "forge" => Ok(Modloader::Forge), | ||
22 | "fabric" => Ok(Modloader::Fabric), | ||
23 | "quilt" => Ok(Modloader::Quilt), | ||
24 | _ => { | ||
25 | Err(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER")) | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl Display for Modloader { | ||
32 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
33 | match self { | ||
34 | Modloader::Fabric => write!(f, "fabric"), | ||
35 | Modloader::Forge => write!(f, "forge"), | ||
36 | Modloader::Quilt => write!(f, "quilt"), | ||
37 | } | ||
38 | } | ||
39 | } | ||
diff --git a/src/data/project.rs b/src/data/project.rs new file mode 100644 index 0000000..9807867 --- /dev/null +++ b/src/data/project.rs | |||
@@ -0,0 +1,12 @@ | |||
1 | use crate::apis::modrinth::Version; | ||
2 | |||
3 | #[derive(Debug, Clone)] | ||
4 | pub struct ProjectInfo { | ||
5 | pub mod_id: String, | ||
6 | pub slug: String, | ||
7 | pub title: String, | ||
8 | pub current_version: Option<Version>, | ||
9 | pub applicable_versions: Vec<String>, | ||
10 | pub download_link: String, | ||
11 | pub set_version: bool, | ||
12 | } | ||
@@ -4,8 +4,8 @@ use rusqlite::Connection; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | config::Cfg, | 6 | config::Cfg, |
7 | data::{list::List, modloader::Modloader}, | ||
7 | error::{EType, MLErr, MLE}, | 8 | error::{EType, MLErr, MLE}, |
8 | List, Modloader, | ||
9 | }; | 9 | }; |
10 | 10 | ||
11 | //MODS | 11 | //MODS |
diff --git a/src/files.rs b/src/files.rs index 636c934..98785fd 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -10,12 +10,7 @@ use std::{ | |||
10 | use tokio::task::JoinSet; | 10 | use tokio::task::JoinSet; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | cache::{copy_cached_version, get_cached_versions}, | 13 | apis::modrinth::Version, cache::{copy_cached_version, get_cached_versions}, config::Cfg, data::list::List, db::{mods_get_info, userlist_add_disabled_versions}, error::{EType, MLErr, MLE}, PROGRESS_CHARS, STYLE_BAR_BYTE, STYLE_BAR_POS, STYLE_SPINNER |
14 | config::Cfg, | ||
15 | db::{mods_get_info, userlist_add_disabled_versions}, | ||
16 | error::{EType, MLErr, MLE}, | ||
17 | modrinth::Version, | ||
18 | List, PROGRESS_CHARS, STYLE_BAR_BYTE, STYLE_BAR_POS, STYLE_SPINNER, | ||
19 | }; | 14 | }; |
20 | 15 | ||
21 | /// # Errors | 16 | /// # Errors |
diff --git a/src/main.rs b/src/main.rs index a1f0c31..038e2f4 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,12 +1,20 @@ | |||
1 | use clap::{Parser, Subcommand}; | 1 | use clap::{Parser, Subcommand}; |
2 | use modlist::{ | 2 | |
3 | config::Cfg, | 3 | pub mod apis; |
4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, | 4 | pub mod cache; |
5 | download, | 5 | pub mod commands; |
6 | error::MLE, | 6 | pub mod config; |
7 | export, import, mod_add, mod_remove, update, AddMod, IDSelector, | 7 | pub mod db; |
8 | List, Modloader, VersionLevel, | 8 | pub mod error; |
9 | }; | 9 | pub mod files; |
10 | pub mod data; | ||
11 | |||
12 | use commands::{download::download, io::{export, import}, list, modification::{mod_add, mod_remove}, update::update}; | ||
13 | use config::Cfg; | ||
14 | use data::{gameversion::VersionLevel, list::List, modification::{AddMod, IDSelector}, modloader::Modloader}; | ||
15 | pub use data::{STYLE_BAR_POS, STYLE_MESSAGE, STYLE_SPINNER, STYLE_BAR_BYTE, STYLE_OPERATION, PROGRESS_CHARS}; | ||
16 | use db::{config_get_current_list, lists_get, lists_get_all_ids}; | ||
17 | use error::MLE; | ||
10 | 18 | ||
11 | #[derive(Parser)] | 19 | #[derive(Parser)] |
12 | #[command(author, version, about)] | 20 | #[command(author, version, about)] |
@@ -308,16 +316,16 @@ async fn handle_list( | |||
308 | .unwrap(), | 316 | .unwrap(), |
309 | }; | 317 | }; |
310 | 318 | ||
311 | List::add(&config, &id, &ver, &ml, &directory) | 319 | list::add(&config, &id, &ver, &ml, &directory) |
312 | } | 320 | } |
313 | ListCommands::Remove { id } => List::remove(&config, &id), | 321 | ListCommands::Remove { id } => list::remove(&config, &id), |
314 | ListCommands::List => List::list(&config), | 322 | ListCommands::List => list::list(&config), |
315 | ListCommands::Change { id } => List::change(&config, &id), | 323 | ListCommands::Change { id } => list::change(&config, &id), |
316 | ListCommands::Version { | 324 | ListCommands::Version { |
317 | id, | 325 | id, |
318 | version, | 326 | version, |
319 | download, | 327 | download, |
320 | remove, | 328 | remove, |
321 | } => List::version(&config, &id, version, download, remove).await, | 329 | } => list::version(&config, &id, version, download, remove).await, |
322 | } | 330 | } |
323 | } | 331 | } |