From 43206da6f40027715582599baa0ad1c91477539e Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 22 Dec 2022 19:18:56 +0100 Subject: added current list info --- src/commands/list.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/commands/list.rs') diff --git a/src/commands/list.rs b/src/commands/list.rs index 096ce65..bc9e67e 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -17,7 +17,7 @@ pub fn list(config: Cfg, input: Input) -> Result<(), Box> add(config, input.args.ok_or("")?) }, Subcmd::Change => { - change(config, input.args.ok_or("")?) + change(config, input.args) }, Subcmd::Remove => { remove(config, input.args.ok_or("")?) @@ -48,16 +48,18 @@ fn add(config: Cfg, args: Vec) -> Result<(), Box> } } -fn change(config: Cfg, args: Vec) -> Result<(), Box> { +fn change(config: Cfg, args: Option>) -> Result<(), Box> { let lists = lists_get_all_ids(config.clone())?; - match args.len() { + if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) }; + let argsvec = args.ok_or("BAH")?; + match argsvec.len() { 1 => { - let list = String::from(&args[0]); + let list = String::from(&argsvec[0]); if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; config_change_current_list(config, list) }, 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), - _ => panic!("list arguments should never be zero or lower"), + _ => panic!("list arguments should never lower than zero"), } } -- cgit v1.2.3