diff options
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r-- | src/commands/list.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/commands/list.rs b/src/commands/list.rs index 6c260ce..3dfe1ad 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -1,12 +1,19 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{db::{insert_list, remove_list, change_list, get_lists, get_current_list}, Modloader, config::Cfg, input::Input}; | 3 | use crate::{db::{insert_list, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; |
4 | |||
5 | #[derive(Clone)] | ||
6 | pub struct List { | ||
7 | pub id: String, | ||
8 | pub mc_version: String, | ||
9 | pub modloader: Modloader, | ||
10 | } | ||
4 | 11 | ||
5 | 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>> { |
6 | 13 | ||
7 | if args.is_none() { | 14 | if args.is_none() { |
8 | let lists = get_lists(config.clone())?; | 15 | let lists = get_lists(config.clone())?; |
9 | let current_list = get_current_list(config)?; | 16 | let current_list = get_current_list_id(config)?; |
10 | 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); |
11 | return Ok(()); | 18 | return Ok(()); |
12 | } | 19 | } |
@@ -29,6 +36,11 @@ pub fn list(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::e | |||
29 | } | 36 | } |
30 | } | 37 | } |
31 | 38 | ||
39 | pub fn get_current_list(config: Cfg) -> Result<List, Box<dyn std::error::Error>> { | ||
40 | let id = get_current_list_id(config.clone())?; | ||
41 | get_list(config, id) | ||
42 | } | ||
43 | |||
32 | 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>> { |
33 | match args.len() { | 45 | match args.len() { |
34 | 1 | 2 => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))), | 46 | 1 | 2 => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))), |