summaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-01 23:00:45 +0100
committerfxqnlr <[email protected]>2022-11-01 23:00:45 +0100
commitb125dfd03084fff47ab8e90d002c6699b762d998 (patch)
tree151677fb5e88105c06e1072c2fa309f55afaba36 /src/input.rs
parentd38f09a247b8bf1ed328c342f84b74581905317d (diff)
downloadmodlist-b125dfd03084fff47ab8e90d002c6699b762d998.tar
modlist-b125dfd03084fff47ab8e90d002c6699b762d998.tar.gz
modlist-b125dfd03084fff47ab8e90d002c6699b762d998.zip
added list stuff + beginnings of mods
Diffstat (limited to 'src/input.rs')
-rw-r--r--src/input.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/input.rs b/src/input.rs
index 689389e..061f1fd 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,5 +1,5 @@
1use std::io::{stdin, Error, ErrorKind}; 1use std::io::{stdin, Error, ErrorKind};
2use crate::{add, config::Cfg}; 2use crate::{add, config::Cfg, list};
3 3
4pub struct Input { 4pub struct Input {
5 pub command: String, 5 pub command: String,
@@ -9,14 +9,9 @@ pub struct Input {
9impl Input { 9impl Input {
10 pub fn from(string: String) -> Result<Self, Box<dyn std::error::Error>> { 10 pub fn from(string: String) -> Result<Self, Box<dyn std::error::Error>> {
11 let mut split: Vec<&str> = string.split(' ').collect(); 11 let mut split: Vec<&str> = string.split(' ').collect();
12
13 let command: String; 12 let command: String;
14 let mut args: Option<Vec<String>> = None; 13 let mut args: Option<Vec<String>> = None;
15
16 if split[0].is_empty() { split.remove(0); }; 14 if split[0].is_empty() { split.remove(0); };
17
18 dbg!(&split);
19
20 match split.len() { 15 match split.len() {
21 0 => { Err(Box::new(Error::new(ErrorKind::InvalidInput, "NO_ARGS"))) } 16 0 => { Err(Box::new(Error::new(ErrorKind::InvalidInput, "NO_ARGS"))) }
22 1 => Ok( Input { command: split[0].to_string(), args }), 17 1 => Ok( Input { command: split[0].to_string(), args }),
@@ -43,8 +38,6 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
43 .read_line(&mut user_input) 38 .read_line(&mut user_input)
44 .expect("ERROR"); 39 .expect("ERROR");
45 40
46 dbg!(&user_input);
47
48 let input = Input::from(user_input.trim().to_string())?; 41 let input = Input::from(user_input.trim().to_string())?;
49 42
50 match input.command.as_str() { 43 match input.command.as_str() {
@@ -54,6 +47,9 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
54 add(config, input.args.unwrap()[0].to_string()).await?; 47 add(config, input.args.unwrap()[0].to_string()).await?;
55 Ok(()) 48 Ok(())
56 }, 49 },
50 "list" => {
51 list(config, input.args)
52 },
57 _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_COMMAND"))), 53 _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_COMMAND"))),
58 } 54 }
59} 55}