summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-01-19 18:37:42 +0100
committerfxqnlr <[email protected]>2023-01-19 18:37:42 +0100
commitf7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 (patch)
tree21d0c7356b55e9b45517fd9ca874dd3270b6bc3a /src/commands/list.rs
parentbe9f74f4fb82b25abd99f7024e0f5eea2691f34f (diff)
downloadmodlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.tar
modlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.tar.gz
modlist-f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537.zip
input mostly inplemented, mods missing
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs73
1 files changed, 21 insertions, 52 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs
index 2fec1c7..bc58787 100644
--- a/src/commands/list.rs
+++ b/src/commands/list.rs
@@ -1,6 +1,4 @@
1use std::io::{Error, ErrorKind}; 1use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::MLE, /*modrinth::MCVersionType*/};
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, ListOptions}, /*cmd_update,*/ error::{MLE, ErrorType, MLError}, /*modrinth::MCVersionType*/};
4 2
5#[derive(Debug, Clone, PartialEq, Eq)] 3#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct List { 4pub struct List {
@@ -9,78 +7,49 @@ pub struct List {
9 pub modloader: Modloader, 7 pub modloader: Modloader,
10 pub download_folder: String, 8 pub download_folder: String,
11} 9}
12/*
13pub async fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
14 10
15 match input.list_options.ok_or("")? { 11pub async fn list(config: Cfg, input: Input) -> MLE<()> {
12
13 match input.clone().list_options.unwrap() {
16 ListOptions::Add => { 14 ListOptions::Add => {
17 match add(config, input.args.ok_or("")?) { 15 add(config, input)
18 Ok(..) => Ok(()),
19 Err(e) => Err(Box::new(e))
20 }
21 }, 16 },
22 ListOptions::Change => { 17 ListOptions::Change => {
23 change(config, input.args) 18 change(config, input)
24 }, 19 },
25 ListOptions::Remove => { 20 ListOptions::Remove => {
26 match remove(config, input.args.ok_or("")?) { 21 remove(config, input)
27 Ok(..) => Ok(()),
28 Err(e) => Err(Box::new(e))
29 }
30 }, 22 },
23 /*
31 Subcmd::Version => { 24 Subcmd::Version => {
32 match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await { 25 match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await {
33 Ok(..) => Ok(()), 26 Ok(..) => Ok(()),
34 Err(e) => Err(Box::new(e)) 27 Err(e) => Err(Box::new(e))
35 } 28 }
36 } 29 }*/
37 _ => {
38 Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND")))
39 }
40 } 30 }
41} 31}
42*/ 32
43pub fn get_current_list(config: Cfg) -> MLE<List> { 33pub fn get_current_list(config: Cfg) -> MLE<List> {
44 let id = config_get_current_list(config.clone())?; 34 let id = config_get_current_list(config.clone())?;
45 lists_get(config, id) 35 lists_get(config, id)
46} 36}
47 37
48fn add(config: Cfg, args: Vec<String>) -> MLE<()> { 38fn add(config: Cfg, input: Input) -> MLE<()> {
49 match args.len() { 39 let id = input.list_id.unwrap();
50 1 | 2 | 3 => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_FEW_ARGUMENTS")), 40 let mc_version = input.list_mcversion.unwrap();
51 4 => { 41 let mod_loader = input.modloader.unwrap();
52 let id = String::from(&args[0]); 42 let download_folder = input.directory.unwrap();
53 let mc_version = String::from(&args[1]); 43 lists_insert(config, id, mc_version, mod_loader, download_folder)
54 let mod_loader = Modloader::from(&args[2])?;
55 let download_folder = String::from(&args[3]);
56 lists_insert(config, id, mc_version, mod_loader, download_folder)
57 },
58 5.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")),
59 _ => panic!("list arguments should never be zero or lower"),
60 }
61} 44}
62 45
63fn change(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { 46fn change(config: Cfg, input: Input) -> MLE<()> {
64 let lists = lists_get_all_ids(config.clone())?; 47 //TODO reimplement current list
65 if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) }; 48 config_change_current_list(config, input.list.unwrap().id)
66 let argsvec = args.ok_or("BAH")?;
67 match argsvec.len() {
68 1 => {
69 let list = String::from(&argsvec[0]);
70 if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); };
71 config_change_current_list(config, list)
72 },
73 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))),
74 _ => panic!("list arguments should never lower than zero"),
75 }
76} 49}
77 50
78fn remove(config: Cfg, args: Vec<String>) -> MLE<()> { 51fn remove(config: Cfg, input: Input) -> MLE<()> {
79 match args.len() { 52 lists_remove(config, input.list.unwrap().id)
80 1 => lists_remove(config, String::from(&args[0])),
81 2.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")),
82 _ => panic!("list arguments should never be zero or lower"),
83 }
84} 53}
85 54
86/* 55/*