pub fn execute(
    shell: &mut Shell, 
    job: Job, 
    background: bool,
    capture: bool,
) -> Result<CommandResult, ShellError> {

    let mut cmds: Vec<Cmd> = Vec::new();
    for cmd in job.cmds {
        cmds.push(Cmd::from_tokencmd(shell, cmd)?)
    }

    if cmds.len() < 1 {
        return Err(
            ShellError::from("oyster: empty job")
        )
    }

    if cmds.len() == 1 && !capture { //no pipeline
        let mut cmd = cmds[0].clone();
        if shell::assign_variables(shell, &mut cmd.cmd) {
            return Ok(CommandResult::new());
        }
        if Path::new(&cmd.cmd).is_dir() {
            let status = cd::run(shell, cmd, true);
            return Ok(CommandResult::from_status(status))
        }
        match cmd.cmd.as_str() {
            "cd" => {
                let status = cd::run(shell, cmd, false);
                return Ok(CommandResult::from_status(status));
            }
            "bg" => {
                let status = bg::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "fg" => {
                let status = fg::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "jobs" => {
                let status = jobs::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "alias" => {
                let status = alias::set(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "unalias" => {
                let status = alias::unset(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "let" => {
                let status = set::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "which" => {
                let status = which::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "show" => {
                let status = show::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "pushd" => {
                let status = dirstack::pushd(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "popd" => {
                let status = dirstack::popd(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "dirs" => {
                let status = dirstack::dirs(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "eval" => {
            }
            "source" => {
            }
            "export" => {
                let status = export::run(cmd);
                return Ok(CommandResult::from_status(status));
            }
            "echo" => {
            }
            "kill" => {
            }
            "exit" => {
                let status = exit::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            _ => {}
        }
    }
    
    let (given, result) = core::run_pipeline(
        shell, job.id, cmds, background, capture
    )?;
    if given {
        let pgid = getpgid(None)?;
        shell::give_terminal_to(pgid)?;
    }
    Ok(result)
}
/// Lower level control. Executes single pipeline.
/// Checks for builtins without pipeline
Lower level control. Executes single pipeline.
Checks for builtins without pipeline
Lower level control . Executes single pipeline . Checks for builtins without pipeline
pub fn execute(
    shell: &mut Shell, 
    job: Job, 
    background: bool,
    capture: bool,
) -> Result<CommandResult, ShellError> {
    let mut cmds: Vec<Cmd> = Vec::new();
    for cmd in job.cmds {
        cmds.push(Cmd::from_tokencmd(shell, cmd)?)
    }
    if cmds.len() < 1 {
        return Err(
            ShellError::from("oyster: empty job")
        )
    }
    if cmds.len() == 1 && !capture { //no pipeline
        let mut cmd = cmds[0].clone();
        if shell::assign_variables(shell, &mut cmd.cmd) {
            return Ok(CommandResult::new());
        }
        if Path::new(&cmd.cmd).is_dir() {
            let status = cd::run(shell, cmd, true);
            return Ok(CommandResult::from_status(status))
        }
        match cmd.cmd.as_str() {
            "cd" => {
                let status = cd::run(shell, cmd, false);
                return Ok(CommandResult::from_status(status));
            }
            "bg" => {
                let status = bg::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "fg" => {
                let status = fg::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "jobs" => {
                let status = jobs::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "alias" => {
                let status = alias::set(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "unalias" => {
                let status = alias::unset(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "let" => {
                let status = set::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "which" => {
                let status = which::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "show" => {
                let status = show::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "pushd" => {
                let status = dirstack::pushd(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "popd" => {
                let status = dirstack::popd(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "dirs" => {
                let status = dirstack::dirs(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            "eval" => {
            }
            "source" => {
            }
            "export" => {
                let status = export::run(cmd);
                return Ok(CommandResult::from_status(status));
            }
            "echo" => {
            }
            "kill" => {
            }
            "exit" => {
                let status = exit::run(shell, cmd);
                return Ok(CommandResult::from_status(status));
            }
            _ => {}
        }
    }
    let (given, result) = core::run_pipeline(
        shell, job.id, cmds, background, capture
    )?;
    if given {
        let pgid = getpgid(None)?;
        shell::give_terminal_to(pgid)?;
    }
    Ok(result)
}
pub fn execute ( shell : & mut Shell , job : Job , background : bool , capture : bool , ) -> Result < CommandResult , ShellError > { let mut cmds : Vec < Cmd > = Vec :: new ( ) ; for cmd in job . cmds { cmds . push ( Cmd :: from_tokencmd ( shell , cmd ) ? ) } if cmds . len ( ) < 1 { return Err ( ShellError :: from ( " " ) ) } if cmds . len ( ) == 1 && ! capture { //no pipeline let mut cmd = cmds [ 0 ] . clone ( ) ; if shell :: assign_variables ( shell , & mut cmd . cmd ) { return Ok ( CommandResult :: new ( ) ) ; } if Path :: new ( & cmd . cmd ) . is_dir ( ) { let status = cd :: run ( shell , cmd , true ) ; return Ok ( CommandResult :: from_status ( status ) ) } match cmd . cmd . as_str ( ) { " " => { let status = cd :: run ( shell , cmd , false ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = bg :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = fg :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = jobs :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = alias :: set ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = alias :: unset ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = set :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = which :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = show :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = dirstack :: pushd ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = dirstack :: popd ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { let status = dirstack :: dirs ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { } " " => { } " " => { let status = export :: run ( cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } " " => { } " " => { } " " => { let status = exit :: run ( shell , cmd ) ; return Ok ( CommandResult :: from_status ( status ) ) ; } _ => { } } } let ( given , result ) = core :: run_pipeline ( shell , job . id , cmds , background , capture ) ? ; if given { let pgid = getpgid ( None ) ? ; shell :: give_terminal_to ( pgid ) ? ; } Ok ( result ) }
Lower level control.
Lower level control .
shell
&mut Shell
job
Job
background
bool
capture
bool