summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/download.rs2
-rw-r--r--src/commands/io.rs7
-rw-r--r--src/commands/list.rs193
-rw-r--r--src/commands/mod.rs11
-rw-r--r--src/commands/modification.rs35
-rw-r--r--src/commands/update.rs11
6 files changed, 95 insertions, 164 deletions
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 @@
1use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 1use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
2 2
3use crate::apis::modrinth::get_raw_versions;
3use crate::{config::Cfg, List}; 4use crate::{config::Cfg, List};
4use crate::{ 5use 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};
13use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; 13use 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;
4use std::io::prelude::*; 4use std::io::prelude::*;
5 5
6use crate::{ 6use 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 @@
1use indicatif::{ProgressBar, ProgressStyle}; 1use indicatif::{ProgressBar, ProgressStyle};
2 2
3use crate::{ 3use 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
14pub struct List { 11pub 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
21impl List { 30/// # Errors
22 /// # Errors 31pub 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<()> { 50pub 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( 70pub 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<()> { 98pub 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 @@
1pub mod download;
2pub mod io;
3pub mod list;
4pub mod modification;
5pub mod update;
6
7pub use download::*;
8pub use io::*;
9pub use list::*;
10pub use modification::*;
11pub 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;
3use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 3use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
4 4
5use crate::{ 5use 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)]
22pub struct AddMod {
23 pub id: IDSelector,
24 pub set_version: bool,
25}
26
27#[derive(Debug, PartialEq, Eq)]
28pub enum IDSelector {
29 ModificationID(String),
30 VersionID(String),
31}
32
33#[derive(Debug, Clone)]
34pub 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
45pub async fn mod_add( 14pub 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 @@
1use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 1use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
2 2
3use crate::{ 3use 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