aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-06-09 10:52:47 -0400
committerJesse Luehrs <doy@tozt.net>2019-06-09 10:52:47 -0400
commit035c598646d54ac0dc55fb9161e2f42e1863529e (patch)
tree09b7c7df5477e34ec226059cdcca5dc26fa8c022
parent8238346dc745319bf5289be24176915940da96f6 (diff)
downloadnbsh-old-035c598646d54ac0dc55fb9161e2f42e1863529e.tar.gz
nbsh-old-035c598646d54ac0dc55fb9161e2f42e1863529e.zip
refactor
-rw-r--r--src/main.rs1
-rw-r--r--src/parser.rs14
-rw-r--r--src/process.rs7
-rw-r--r--src/repl.rs5
4 files changed, 24 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 1d78e10..d283021 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
+mod parser;
mod process;
mod readline;
mod repl;
diff --git a/src/parser.rs b/src/parser.rs
new file mode 100644
index 0000000..cc86020
--- /dev/null
+++ b/src/parser.rs
@@ -0,0 +1,14 @@
+#[derive(Debug)]
+pub enum Error {
+ 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)
+ }
+}
diff --git a/src/process.rs b/src/process.rs
index 0c7b61f..5a82e5c 100644
--- a/src/process.rs
+++ b/src/process.rs
@@ -6,6 +6,7 @@ use tokio_pty_process::CommandExt;
#[derive(Debug)]
pub enum Error {
IOError(std::io::Error),
+ ParserError(crate::parser::Error),
}
pub fn spawn(line: &str) -> Result<RunningProcess, Error> {
@@ -34,10 +35,10 @@ impl RunningProcess {
let pty = tokio_pty_process::AsyncPtyMaster::open()
.map_err(|e| Error::IOError(e))?;
- let mut argv: Vec<_> = line.split(' ').collect();
- let cmd = argv.remove(0);
+ let (cmd, args) =
+ crate::parser::parse(line).map_err(|e| Error::ParserError(e))?;
let process = std::process::Command::new(cmd)
- .args(&argv)
+ .args(&args)
.spawn_pty_async(&pty)
.map_err(|e| Error::IOError(e))?;
diff --git a/src/repl.rs b/src/repl.rs
index e05624e..e54eb22 100644
--- a/src/repl.rs
+++ b/src/repl.rs
@@ -42,6 +42,11 @@ pub fn repl() {
Err(Error::ReadError(crate::readline::Error::EOF)) => {
return Ok((done, true));
}
+ Err(Error::EvalError(crate::process::Error::ParserError(
+ crate::parser::Error::CommandRequired,
+ ))) => {
+ return Ok((done, false));
+ }
Err(e) => {
let stderr = std::io::stderr();
let mut stderr = stderr.lock();