Browse Source

fix: continue on empty line

main
fdai7381 2 years ago
committed by fdai7451
parent
commit
c108575dfa
  1. 1
      src/error.rs
  2. 3
      src/execute.rs
  3. 3
      src/main.rs

1
src/error.rs

@ -1,3 +1,4 @@
pub enum ShellError { pub enum ShellError {
EmptyLine,
Execute(String), Execute(String),
} }

3
src/execute.rs

@ -5,6 +5,9 @@ use crate::error::ShellError::Execute;
use crate::parse::parse_line; use crate::parse::parse_line;
pub fn interpret(line: &str) -> Result<(), ShellError> { pub fn interpret(line: &str) -> Result<(), ShellError> {
if line.is_empty() {
return Err(ShellError::EmptyLine);
}
let (keyword, args) = parse_line(line); let (keyword, args) = parse_line(line);
let mut command = Command::new(keyword); let mut command = Command::new(keyword);

3
src/main.rs

@ -21,6 +21,9 @@ fn main() -> Result<()> {
match readline { match readline {
Ok(line) => match interpret(&line) { Ok(line) => match interpret(&line) {
Ok(_) => {} Ok(_) => {}
Err(ShellError::EmptyLine) => {
continue;
}
Err(ShellError::Execute(err)) => { Err(ShellError::Execute(err)) => {
eprintln!("{}", err) eprintln!("{}", err)
} }

Loading…
Cancel
Save