2019-05-22 09:12:03 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use subprocess::Exec;
|
|
|
|
|
|
|
|
crate enum ClassifiedCommand {
|
|
|
|
Internal(InternalCommand),
|
|
|
|
External(ExternalCommand),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ClassifiedCommand {
|
|
|
|
crate fn run(
|
|
|
|
self,
|
|
|
|
input: VecDeque<Value>,
|
2019-05-23 06:30:43 +02:00
|
|
|
context: &mut Context,
|
2019-05-22 09:12:03 +02:00
|
|
|
) -> Result<VecDeque<Value>, ShellError> {
|
|
|
|
match self {
|
|
|
|
ClassifiedCommand::Internal(internal) => {
|
|
|
|
let result = context.run_command(internal.command, internal.args, input)?;
|
|
|
|
|
|
|
|
let mut next = VecDeque::new();
|
|
|
|
|
|
|
|
for v in result {
|
|
|
|
match v {
|
|
|
|
ReturnValue::Action(action) => match action {
|
2019-05-23 06:30:43 +02:00
|
|
|
CommandAction::ChangeCwd(cwd) => context.env.cwd = cwd,
|
2019-05-22 09:12:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ReturnValue::Value(v) => next.push_back(v),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(next)
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassifiedCommand::External(external) => {
|
|
|
|
Exec::shell(&external.name)
|
|
|
|
.args(&external.args)
|
|
|
|
.cwd(context.env.cwd())
|
|
|
|
.join()
|
|
|
|
.unwrap();
|
|
|
|
Ok(VecDeque::new())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crate struct InternalCommand {
|
|
|
|
crate command: Arc<dyn Command>,
|
|
|
|
crate args: Vec<Value>,
|
|
|
|
}
|
|
|
|
|
|
|
|
crate struct ExternalCommand {
|
|
|
|
crate name: String,
|
|
|
|
crate args: Vec<String>,
|
|
|
|
}
|