mirror of
https://github.com/nushell/nushell.git
synced 2025-05-23 16:11:18 +00:00
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.
39 lines
856 B
Rust
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>;
|
|
}
|