diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-04-11 20:45:11 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-04-11 20:45:11 +0200 |
commit | e6ed91d0efab436c8a1ca4b6f701b6a9a4d96ccd (patch) | |
tree | d246e448c6cbd86df795452c220f39723d09a714 /src/parser.rs | |
parent | 972319c1811e1a9c4f491a03ba92ea5a624cca5e (diff) |
Refactoring, move where whitespace is handled
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/parser.rs b/src/parser.rs index 3a7d129..38b88f3 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -8,8 +8,6 @@ use thiserror::Error; #[derive(Parser, Clone, Debug, PartialEq, Eq)] #[command(name = "")] pub enum ShackleCommand { - #[command(skip)] - Whitespace, Exit, /// List all repositories available List, @@ -80,17 +78,13 @@ impl FromStr for ShackleCommand { fn from_str(s: &str) -> Result<Self, Self::Err> { let trimmed = s.trim(); - if trimmed.len() == 0 { - Ok(ShackleCommand::Whitespace) - } else { - let lexed = shlex::split(trimmed); - match lexed { - None => Err(ParserError::LexerError("Incomplete input".to_string())), - Some(lexed) => { - let parsed = - ShackleCommand::try_parse_from(["".to_owned()].into_iter().chain(lexed))?; - Ok(parsed) - } + let lexed = shlex::split(trimmed); + match lexed { + None => Err(ParserError::LexerError("Incomplete input".to_string())), + Some(lexed) => { + let parsed = + ShackleCommand::try_parse_from(["".to_owned()].into_iter().chain(lexed))?; + Ok(parsed) } } } @@ -154,12 +148,4 @@ mod test { }) ); } - - #[test] - fn it_parses_whitespace_correctly() { - assert_eq!( - " ".parse::<ShackleCommand>().unwrap(), - ShackleCommand::Whitespace - ); - } } |