nushell/src/commands/command.rs
Yehuda Katz ceb0487eba A bunch of rework
I'm gonna use a VecDeque now instead of trying to get async streams
working to make progress, but the intent is that we should be able to
use async streams in and out to interleave the work better.
2019-05-13 13:30:51 -04:00

39 lines
856 B
Rust

use crate::errors::ShellError;
use crate::object::Value;
use crate::prelude::*;
use std::path::PathBuf;
pub trait CommandBlueprint {
fn create(
&self,
input: Vec<Value>,
host: &dyn crate::Host,
env: &mut crate::Environment,
) -> Result<Box<dyn Command>, ShellError>;
}
pub enum CommandAction {
ChangeCwd(PathBuf),
}
pub enum ReturnValue {
Value(Value),
Action(CommandAction),
}
impl ReturnValue {
crate fn single(value: Value) -> VecDeque<ReturnValue> {
let mut v = VecDeque::new();
v.push_back(ReturnValue::Value(value));
v
}
crate fn change_cwd(path: PathBuf) -> ReturnValue {
ReturnValue::Action(CommandAction::ChangeCwd(path))
}
}
pub trait Command {
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError>;
}