summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-01-09 23:12:52 +0100
committerfxqnlr <[email protected]>2023-01-09 23:12:52 +0100
commit89193143f90e1b8cbb91445d14942fa39509acbb (patch)
tree4aeb60ae2aceffc2468589c615ead9dc7079a34d /src/commands/list.rs
parent94d7656cce4ca751be545eeb2ff52bdea1f37fa0 (diff)
downloadmodlist-89193143f90e1b8cbb91445d14942fa39509acbb.tar
modlist-89193143f90e1b8cbb91445d14942fa39509acbb.tar.gz
modlist-89193143f90e1b8cbb91445d14942fa39509acbb.zip
implemented more Error (dumb)
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs32
1 files changed, 23 insertions, 9 deletions
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 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use 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}}; 3use 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)]
6pub struct List { 6pub 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
34pub fn get_current_list(config: Cfg) -> Result<List, Box<dyn std::error::Error>> { 40pub 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
39fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { 45fn 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
77fn 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
88async 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(&current_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}