summaryrefslogtreecommitdiff
path: root/src/commands/list.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-03 21:34:04 +0100
committerfxqnlr <[email protected]>2022-11-03 21:34:04 +0100
commit96cc5257de09682df345e768dc2a91303f9b36c9 (patch)
treef505d14c581e2bef4cfe222bd1069661bedd22e0 /src/commands/list.rs
parentb125dfd03084fff47ab8e90d002c6699b762d998 (diff)
downloadmodlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar
modlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar.gz
modlist-96cc5257de09682df345e768dc2a91303f9b36c9.zip
added update beginnings; init of tests
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r--src/commands/list.rs16
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 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use crate::{db::{insert_list, remove_list, change_list, get_lists, get_current_list}, Modloader, config::Cfg, input::Input}; 3use 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)]
6pub struct List {
7 pub id: String,
8 pub mc_version: String,
9 pub modloader: Modloader,
10}
4 11
5pub fn list(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { 12pub 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
39pub 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
32fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { 44fn 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"))),