summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/list.rs12
1 files changed, 7 insertions, 5 deletions
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<dyn std::error::Error>>
17 add(config, input.args.ok_or("")?) 17 add(config, input.args.ok_or("")?)
18 }, 18 },
19 Subcmd::Change => { 19 Subcmd::Change => {
20 change(config, input.args.ok_or("")?) 20 change(config, input.args)
21 }, 21 },
22 Subcmd::Remove => { 22 Subcmd::Remove => {
23 remove(config, input.args.ok_or("")?) 23 remove(config, input.args.ok_or("")?)
@@ -48,16 +48,18 @@ fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>>
48 } 48 }
49} 49}
50 50
51fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { 51fn change(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> {
52 let lists = lists_get_all_ids(config.clone())?; 52 let lists = lists_get_all_ids(config.clone())?;
53 match args.len() { 53 if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) };
54 let argsvec = args.ok_or("BAH")?;
55 match argsvec.len() {
54 1 => { 56 1 => {
55 let list = String::from(&args[0]); 57 let list = String::from(&argsvec[0]);
56 if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; 58 if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); };
57 config_change_current_list(config, list) 59 config_change_current_list(config, list)
58 }, 60 },
59 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), 61 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))),
60 _ => panic!("list arguments should never be zero or lower"), 62 _ => panic!("list arguments should never lower than zero"),
61 } 63 }
62} 64}
63 65