diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-07-06 14:44:50 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-07-06 14:44:50 -0400 |
commit | fa2aef91c23ade9b1a4ef4bf7e00f3202d543854 (patch) | |
tree | dc736a4430d71059d7d5c45cb6475b8af510d314 | |
parent | d5aa9a797d640650f019c4e7dbc9e0a2229a29fa (diff) | |
download | nbsh-old-fa2aef91c23ade9b1a4ef4bf7e00f3202d543854.tar.gz nbsh-old-fa2aef91c23ade9b1a4ef4bf7e00f3202d543854.zip |
make exit handling more consistent
-rw-r--r-- | src/builtins.rs | 13 | ||||
-rw-r--r-- | src/eval.rs | 3 | ||||
-rw-r--r-- | src/process.rs | 2 | ||||
-rw-r--r-- | src/repl.rs | 5 |
4 files changed, 15 insertions, 8 deletions
diff --git a/src/builtins.rs b/src/builtins.rs index 2393e89..83fa0d1 100644 --- a/src/builtins.rs +++ b/src/builtins.rs @@ -1,4 +1,5 @@ use snafu::{OptionExt as _, ResultExt as _}; +use std::os::unix::process::ExitStatusExt as _; #[derive(Debug, snafu::Snafu)] pub enum Error { @@ -85,9 +86,19 @@ impl futures::stream::Stream for Builtin { }; res.map(|_| { futures::Async::Ready(Some( - crate::eval::CommandEvent::BuiltinExit, + crate::eval::CommandEvent::CommandExit( + std::process::ExitStatus::from_raw(0), + ), )) }) + .or_else(|e| match e { + Error::UnknownBuiltin { .. } => Err(e), + _ => Ok(futures::Async::Ready(Some( + crate::eval::CommandEvent::CommandExit( + std::process::ExitStatus::from_raw(256), + ), + ))), + }) } else { Ok(futures::Async::Ready(None)) } diff --git a/src/eval.rs b/src/eval.rs index 5f789b3..549650d 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -37,8 +37,7 @@ pub fn eval(line: &str) -> Result<Eval> { pub enum CommandEvent { CommandStart(String, Vec<String>), Output(Vec<u8>), - ProcessExit(std::process::ExitStatus), - BuiltinExit, + CommandExit(std::process::ExitStatus), } pub struct Eval { diff --git a/src/process.rs b/src/process.rs index 81899d7..6863b3e 100644 --- a/src/process.rs +++ b/src/process.rs @@ -167,7 +167,7 @@ impl futures::stream::Stream for RunningProcess { Ok(futures::Async::Ready(status)) => { self.exit_done = true; return Ok(futures::Async::Ready(Some( - crate::eval::CommandEvent::ProcessExit(status), + crate::eval::CommandEvent::CommandExit(status), ))); } Ok(futures::Async::NotReady) => { diff --git a/src/repl.rs b/src/repl.rs index 8bd3230..5a028fe 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -87,12 +87,9 @@ fn print(event: &crate::eval::CommandEvent) -> Result<()> { stdout.write(out).context(Print)?; stdout.flush().context(Print)?; } - crate::eval::CommandEvent::ProcessExit(status) => { + crate::eval::CommandEvent::CommandExit(status) => { eprint!("command exited: {}\r\n", status); } - crate::eval::CommandEvent::BuiltinExit => { - eprint!("builtin exited\r\n"); - } } Ok(()) } |