aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/parser.rs b/src/parser.rs
index cc86020..3a03d43 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,14 +1,14 @@
-#[derive(Debug)]
+use snafu::{OptionExt, Snafu};
+
+#[derive(Debug, Snafu)]
pub enum Error {
+ #[snafu(display("No command given"))]
CommandRequired,
}
pub fn parse(line: &str) -> Result<(String, Vec<String>), Error> {
// TODO
let mut tokens = line.split_whitespace().map(|s| s.to_string());
- if let Some(cmd) = tokens.next() {
- Ok((cmd, tokens.collect()))
- } else {
- Err(Error::CommandRequired)
- }
+ let cmd = tokens.next().context(CommandRequired)?;
+ Ok((cmd, tokens.collect()))
}