From 6c3db7752582906245d9d5c70b80823d7a2e4e91 Mon Sep 17 00:00:00 2001 From: fdai7381 Date: Tue, 17 Jan 2023 20:34:44 +0100 Subject: [PATCH] fix: continue on empty line --- src/error.rs | 1 + src/execute.rs | 3 +++ src/main.rs | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/error.rs b/src/error.rs index 291a017..49740d9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,4 @@ pub enum ShellError { + EmptyLine, Execute(String), } diff --git a/src/execute.rs b/src/execute.rs index bfce3d2..362d217 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -5,6 +5,9 @@ use crate::error::ShellError::Execute; use crate::parse::parse_line; pub fn interpret(line: &str) -> Result<(), ShellError> { + if line.is_empty() { + return Err(ShellError::EmptyLine); + } let (keyword, args) = parse_line(line); let mut command = Command::new(keyword); diff --git a/src/main.rs b/src/main.rs index a8ebe92..75728d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,9 @@ fn main() -> Result<()> { match readline { Ok(line) => match interpret(&line) { Ok(_) => {} + Err(ShellError::EmptyLine) => { + continue; + } Err(ShellError::Execute(err)) => { eprintln!("{}", err) }