diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/io.rs | 2 | ||||
-rw-r--r-- | src/commands/list.rs | 32 | ||||
-rw-r--r-- | src/commands/update.rs | 8 |
3 files changed, 28 insertions, 14 deletions
diff --git a/src/commands/io.rs b/src/commands/io.rs index 39f92d5..6c4a4d3 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -28,7 +28,7 @@ impl ExportList { | |||
28 | 28 | ||
29 | let mods = userlist_get_all_ids(config, list_id)?.join("|"); | 29 | let mods = userlist_get_all_ids(config, list_id)?.join("|"); |
30 | 30 | ||
31 | Ok(Self { id: list.id, mods, launcher: list.modloader.stringify(), mc_version: list.mc_version, download_folder: dl_folder }) | 31 | Ok(Self { id: list.id, mods, launcher: list.modloader.to_string(), mc_version: list.mc_version, download_folder: dl_folder }) |
32 | } | 32 | } |
33 | } | 33 | } |
34 | 34 | ||
diff --git a/src/commands/list.rs b/src/commands/list.rs index 585efe2..526b434 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::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, Subcmd}}; | 3 | use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, Subcmd}, cmd_update, error::{MLE, ErrorType, MLError}}; |
4 | 4 | ||
5 | #[derive(Debug, Clone, PartialEq, Eq)] | 5 | #[derive(Debug, Clone, PartialEq, Eq)] |
6 | pub struct List { | 6 | pub struct List { |
@@ -14,7 +14,10 @@ pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::E | |||
14 | 14 | ||
15 | match input.subcommand.ok_or("")? { | 15 | match input.subcommand.ok_or("")? { |
16 | Subcmd::Add => { | 16 | Subcmd::Add => { |
17 | add(config, input.args.ok_or("")?) | 17 | match add(config, input.args.ok_or("")?) { |
18 | Ok(..) => Ok(()), | ||
19 | Err(e) => Err(Box::new(e)) | ||
20 | } | ||
18 | }, | 21 | }, |
19 | Subcmd::Change => { | 22 | Subcmd::Change => { |
20 | change(config, input.args) | 23 | change(config, input.args) |
@@ -23,7 +26,10 @@ pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::E | |||
23 | remove(config, input.args.ok_or("")?) | 26 | remove(config, input.args.ok_or("")?) |
24 | }, | 27 | }, |
25 | Subcmd::Version => { | 28 | Subcmd::Version => { |
26 | version(config, input.args.ok_or("NO_VERSION")?) | 29 | match version(config, input.args.ok_or("NO_VERSION")?).await { |
30 | Ok(..) => Ok(()), | ||
31 | Err(e) => Err(Box::new(e)) | ||
32 | } | ||
27 | } | 33 | } |
28 | _ => { | 34 | _ => { |
29 | Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) | 35 | Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) |
@@ -31,14 +37,14 @@ pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::E | |||
31 | } | 37 | } |
32 | } | 38 | } |
33 | 39 | ||
34 | pub fn get_current_list(config: Cfg) -> Result<List, Box<dyn std::error::Error>> { | 40 | pub fn get_current_list(config: Cfg) -> MLE<List> { |
35 | let id = config_get_current_list(config.clone())?; | 41 | let id = config_get_current_list(config.clone())?; |
36 | lists_get(config, id) | 42 | lists_get(config, id) |
37 | } | 43 | } |
38 | 44 | ||
39 | fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 45 | fn add(config: Cfg, args: Vec<String>) -> MLE<()> { |
40 | match args.len() { | 46 | match args.len() { |
41 | 1 | 2 | 3 => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))), | 47 | 1 | 2 | 3 => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_FEW_ARGUMENTS")), |
42 | 4 => { | 48 | 4 => { |
43 | let id = String::from(&args[0]); | 49 | let id = String::from(&args[0]); |
44 | let mc_version = String::from(&args[1]); | 50 | let mc_version = String::from(&args[1]); |
@@ -46,7 +52,7 @@ fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> | |||
46 | let download_folder = String::from(&args[3]); | 52 | let download_folder = String::from(&args[3]); |
47 | lists_insert(config, id, mc_version, mod_loader, download_folder) | 53 | lists_insert(config, id, mc_version, mod_loader, download_folder) |
48 | }, | 54 | }, |
49 | 5.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), | 55 | 5.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), |
50 | _ => panic!("list arguments should never be zero or lower"), | 56 | _ => panic!("list arguments should never be zero or lower"), |
51 | } | 57 | } |
52 | } | 58 | } |
@@ -74,7 +80,15 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
74 | } | 80 | } |
75 | } | 81 | } |
76 | 82 | ||
77 | fn version(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 83 | ///Changing the current lists version and updating it |
78 | lists_version(config.clone(), config_get_current_list(config.clone())?, String::from(&args[0])) | 84 | /// #Arguments |
85 | /// | ||
86 | /// * `config` - The current config | ||
87 | /// * `args` - All args, to extract the new version | ||
88 | async fn version(config: Cfg, args: Vec<String>) -> MLE<()> { | ||
89 | let current_list = lists_get(config.clone(), config_get_current_list(config.clone())?)?; | ||
90 | |||
91 | lists_version(config.clone(), String::from(¤t_list.id), String::from(&args[0]))?; | ||
79 | //update the list & with -- args | 92 | //update the list & with -- args |
93 | cmd_update(config, vec![current_list], true, true, false).await | ||
80 | } | 94 | } |
diff --git a/src/commands/update.rs b/src/commands/update.rs index 11f283e..ca28130 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}}; | 3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}, error::{MLE, MLError, ErrorType}}; |
4 | 4 | ||
5 | pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn update(config: Cfg, input: Input) -> MLE<()> { |
6 | 6 | ||
7 | let mut liststack: Vec<List> = vec![]; | 7 | let mut liststack: Vec<List> = vec![]; |
8 | if input.all_lists { | 8 | if input.all_lists { |
@@ -19,7 +19,7 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
19 | cmd_update(config, liststack, input.clean, input.direct_download, input.delete_old).await | 19 | cmd_update(config, liststack, input.clean, input.direct_download, input.delete_old).await |
20 | } | 20 | } |
21 | 21 | ||
22 | pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_download: bool, delete_old: bool) -> Result<(), Box<dyn std::error::Error>> { | 22 | pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> { |
23 | for current_list in liststack { | 23 | for current_list in liststack { |
24 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; | 24 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; |
25 | 25 | ||
@@ -37,7 +37,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_d | |||
37 | let current_version = &versions[index]; | 37 | let current_version = &versions[index]; |
38 | let p_id = String::from(&project.id); | 38 | let p_id = String::from(&project.id); |
39 | let v_id = ¤t_version.mod_id; | 39 | let v_id = ¤t_version.mod_id; |
40 | if &p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "SORTING_ERROR"))) }; | 40 | if &p_id != v_id { return Err(MLError::new(ErrorType::Other, "SORTING_ERROR")) }; |
41 | 41 | ||
42 | //Getting current installed version for disable or delete | 42 | //Getting current installed version for disable or delete |
43 | let disable_version = userlist_get_current_version(config.clone(), String::from(¤t_list.id), String::from(&project.id))?; | 43 | let disable_version = userlist_get_current_version(config.clone(), String::from(¤t_list.id), String::from(&project.id))?; |