@ -1,5 +1,7 @@
mod parse;
mod prompt;
use parse::parse_line;
use rustyline::error::ReadlineError;
use rustyline::{Editor, Result};
@ -15,7 +17,9 @@ fn main() -> Result<()> {
match readline {
Ok(line) => {
println!("Line: {}", line);
if let Err(e) = parse_line(&line) {
println!("{}", e)
}
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
@ -0,0 +1,22 @@
use std::{
io::{self, Write},
process::Command,
};
pub fn parse_line(line: &str) -> io::Result<()> {
let tokens = line.trim().split(' ').collect::<Vec<&str>>();
let mut args: &[&str] = &[];
let command = tokens[0];
if !args.is_empty() {
args = &tokens[1..];
let mut command = Command::new(command);
command.args(args);
let output = command.output()?;
io::stderr().write_all(&output.stderr)?;
io::stdout().write_all(&output.stdout)?;
Ok(())