diff options
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r-- | src/commands/list.rs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index ffa5926..6c80e4e 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,8 +1,8 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{db::{lists_insert, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; | 3 | use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get}, Modloader, config::Cfg, input::Input}; |
4 | 4 | ||
5 | #[derive(Clone)] | 5 | #[derive(Debug, Clone, PartialEq, Eq)] |
6 | pub struct List { | 6 | pub struct List { |
7 | pub id: String, | 7 | pub id: String, |
8 | pub mc_version: String, | 8 | pub mc_version: String, |
@@ -12,8 +12,8 @@ pub struct List { | |||
12 | pub fn list(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | 12 | pub fn list(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { |
13 | 13 | ||
14 | if args.is_none() { | 14 | if args.is_none() { |
15 | let lists = get_lists(config.clone())?; | 15 | let lists = lists_get_all_ids(config.clone())?; |
16 | let current_list = get_current_list_id(config)?; | 16 | let current_list = config_get_current_list(config)?; |
17 | println!("Your lists:\n{}\n-----\nCurrently selected list: \"{}\"", lists.join(",\n"), current_list); | 17 | println!("Your lists:\n{}\n-----\nCurrently selected list: \"{}\"", lists.join(",\n"), current_list); |
18 | return Ok(()); | 18 | return Ok(()); |
19 | } | 19 | } |
@@ -37,8 +37,8 @@ pub fn list(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::e | |||
37 | } | 37 | } |
38 | 38 | ||
39 | pub fn get_current_list(config: Cfg) -> Result<List, Box<dyn std::error::Error>> { | 39 | pub fn get_current_list(config: Cfg) -> Result<List, Box<dyn std::error::Error>> { |
40 | let id = get_current_list_id(config.clone())?; | 40 | let id = config_get_current_list(config.clone())?; |
41 | get_list(config, id) | 41 | lists_get(config, id) |
42 | } | 42 | } |
43 | 43 | ||
44 | fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 44 | fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { |
@@ -52,10 +52,7 @@ fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> | |||
52 | "fabric" => Modloader::Fabric, | 52 | "fabric" => Modloader::Fabric, |
53 | _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) | 53 | _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) |
54 | }; | 54 | }; |
55 | match lists_insert(config, id, mc_version, mod_loader) { | 55 | lists_insert(config, id, mc_version, mod_loader) |
56 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, | ||
57 | Ok(()) => Ok(()), | ||
58 | } | ||
59 | }, | 56 | }, |
60 | 5.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), | 57 | 5.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), |
61 | _ => panic!("list arguments should never be zero or lower"), | 58 | _ => panic!("list arguments should never be zero or lower"), |
@@ -63,13 +60,13 @@ fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> | |||
63 | } | 60 | } |
64 | 61 | ||
65 | fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 62 | fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { |
66 | let lists = get_lists(config.clone())?; | 63 | let lists = lists_get_all_ids(config.clone())?; |
67 | match args.len() { | 64 | match args.len() { |
68 | 1 => { | 65 | 1 => { |
69 | let list = String::from(&args[0]); | 66 | let list = String::from(&args[0]); |
70 | if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; | 67 | if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; |
71 | match change_list(config, list) { | 68 | match config_change_current_list(config, list) { |
72 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, | 69 | Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "72"))) }, |
73 | Ok(()) => Ok(()), | 70 | Ok(()) => Ok(()), |
74 | } | 71 | } |
75 | }, | 72 | }, |
@@ -81,8 +78,8 @@ fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
81 | fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 78 | fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { |
82 | match args.len() { | 79 | match args.len() { |
83 | 1 => { | 80 | 1 => { |
84 | match remove_list(config, String::from(&args[0])) { | 81 | match lists_remove(config, String::from(&args[0])) { |
85 | Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, | 82 | Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "85"))) }, |
86 | Ok(()) => Ok(()), | 83 | Ok(()) => Ok(()), |
87 | } | 84 | } |
88 | }, | 85 | }, |