From 889dc4f87b05d838b25428478a8c42dac454a5cf Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 7 Nov 2022 22:29:35 +0100 Subject: finished rusqlite; added all db tests --- src/commands/list.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/commands/list.rs') 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 @@ use std::io::{Error, ErrorKind}; -use crate::{db::{lists_insert, remove_list, change_list, get_lists, get_current_list_id, get_list}, Modloader, config::Cfg, input::Input}; +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}; -#[derive(Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct List { pub id: String, pub mc_version: String, @@ -12,8 +12,8 @@ pub struct List { pub fn list(config: Cfg, args: Option>) -> Result<(), Box> { if args.is_none() { - let lists = get_lists(config.clone())?; - let current_list = get_current_list_id(config)?; + let lists = lists_get_all_ids(config.clone())?; + let current_list = config_get_current_list(config)?; println!("Your lists:\n{}\n-----\nCurrently selected list: \"{}\"", lists.join(",\n"), current_list); return Ok(()); } @@ -37,8 +37,8 @@ pub fn list(config: Cfg, args: Option>) -> Result<(), Box Result> { - let id = get_current_list_id(config.clone())?; - get_list(config, id) + let id = config_get_current_list(config.clone())?; + lists_get(config, id) } fn add(config: Cfg, args: Vec) -> Result<(), Box> { @@ -52,10 +52,7 @@ fn add(config: Cfg, args: Vec) -> Result<(), Box> "fabric" => Modloader::Fabric, _ => return Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_MODLOADER"))) }; - match lists_insert(config, id, mc_version, mod_loader) { - Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, - Ok(()) => Ok(()), - } + lists_insert(config, id, mc_version, mod_loader) }, 5.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), _ => panic!("list arguments should never be zero or lower"), @@ -63,13 +60,13 @@ fn add(config: Cfg, args: Vec) -> Result<(), Box> } fn change(config: Cfg, args: Vec) -> Result<(), Box> { - let lists = get_lists(config.clone())?; + let lists = lists_get_all_ids(config.clone())?; match args.len() { 1 => { let list = String::from(&args[0]); if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; - match change_list(config, list) { - Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, + match config_change_current_list(config, list) { + Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "72"))) }, Ok(()) => Ok(()), } }, @@ -81,8 +78,8 @@ fn change(config: Cfg, args: Vec) -> Result<(), Box) -> Result<(), Box> { match args.len() { 1 => { - match remove_list(config, String::from(&args[0])) { - Err(err) => { Err(Box::new(Error::new(ErrorKind::Other, "TBD"))) }, + match lists_remove(config, String::from(&args[0])) { + Err(..) => { Err(Box::new(Error::new(ErrorKind::Other, "85"))) }, Ok(()) => Ok(()), } }, -- cgit v1.2.3