Commit 7d9584ee authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Fix the not/and/or builtins to not require re-submission to the statement splitter

Closes #607
parent 09640b7a
......@@ -24,6 +24,7 @@ use self::status::status;
use self::source::source;
use self::test::test;
use self::variables::{alias, drop_alias, drop_array, drop_variable};
use types::Array;
use std::env;
use std::error::Error;
......@@ -31,7 +32,8 @@ use std::io::{self, Write};
use std::path::Path;
use parser::Terminator;
use shell::{self, FlowLogic, Shell, ShellHistory};
use parser::pipelines::{PipeItem, Pipeline};
use shell::{self, FlowLogic, Shell, ShellHistory, Job, JobKind};
use shell::job_control::{JobControl, ProcessState};
use shell::status::*;
use sys;
......@@ -244,16 +246,6 @@ fn builtin_drop(args: &[&str], shell: &mut Shell) -> i32 {
}
}
fn builtin_not(args: &[&str], shell: &mut Shell) -> i32 {
let cmd = args[1..].join(" ");
shell.on_command(&cmd);
match shell.previous_status {
SUCCESS => FAILURE,
FAILURE => SUCCESS,
_ => shell.previous_status,
}
}
fn builtin_set(args: &[&str], shell: &mut Shell) -> i32 { set::set(args, shell) }
fn builtin_eval(args: &[&str], shell: &mut Shell) -> i32 {
......@@ -432,11 +424,25 @@ fn builtin_matches(args: &[&str], _: &mut Shell) -> i32 {
}
}
fn args_to_pipeline(args: &[&str]) -> Pipeline {
let owned = args.into_iter().map(|&x| String::from(x)).collect::<Array>();
let pipe_item = PipeItem::new(Job::new(owned, JobKind::And), Vec::new(), Vec::new());
Pipeline { items: vec![pipe_item] }
}
fn builtin_not(args: &[&str], shell: &mut Shell) -> i32 {
shell.run_pipeline(&mut args_to_pipeline(&args[1..]));
match shell.previous_status {
SUCCESS => FAILURE,
FAILURE => SUCCESS,
_ => shell.previous_status,
}
}
fn builtin_and(args: &[&str], shell: &mut Shell) -> i32 {
match shell.previous_status {
SUCCESS => {
let cmd = args[1..].join(" ");
shell.on_command(&cmd);
shell.run_pipeline(&mut args_to_pipeline(&args[1..]));
shell.previous_status
}
_ => shell.previous_status,
......@@ -446,8 +452,7 @@ fn builtin_and(args: &[&str], shell: &mut Shell) -> i32 {
fn builtin_or(args: &[&str], shell: &mut Shell) -> i32 {
match shell.previous_status {
FAILURE => {
let cmd = args[1..].join(" ");
shell.on_command(&cmd);
shell.run_pipeline(&mut args_to_pipeline(&args[1..]));
shell.previous_status
}
_ => shell.previous_status,
......
......@@ -226,7 +226,7 @@ impl<'a> Shell {
}
/// Executes a pipeline and returns the final exit status of the pipeline.
fn run_pipeline(&mut self, pipeline: &mut Pipeline) -> Option<i32> {
pub(crate) fn run_pipeline(&mut self, pipeline: &mut Pipeline) -> Option<i32> {
let command_start_time = SystemTime::now();
// Expand any aliases found
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment