diff options
author | FxQnLr <[email protected]> | 2022-12-22 19:18:56 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-12-22 19:18:56 +0100 |
commit | 43206da6f40027715582599baa0ad1c91477539e (patch) | |
tree | bd56612d66e5db404c6aab175161a5df587cbcf0 /src/commands/list.rs | |
parent | a9a55e91ba313c2d30f5cb806aac9c4fceddaf2e (diff) | |
download | modlist-43206da6f40027715582599baa0ad1c91477539e.tar modlist-43206da6f40027715582599baa0ad1c91477539e.tar.gz modlist-43206da6f40027715582599baa0ad1c91477539e.zip |
added current list info
Diffstat (limited to 'src/commands/list.rs')
-rw-r--r-- | src/commands/list.rs | 12 |
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 | ||
51 | fn change(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 51 | fn 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 | ||