nushell/src/commands/command.rs

41 lines
890 B
Rust
Raw Normal View History

2019-05-10 18:59:12 +02:00
use crate::errors::ShellError;
use crate::object::Value;
use crate::prelude::*;
2019-05-11 10:08:21 +02:00
use std::path::PathBuf;
2019-05-10 18:59:12 +02:00
2019-05-11 10:08:21 +02:00
pub trait CommandBlueprint {
fn create(
&self,
input: Vec<Value>,
2019-05-10 18:59:12 +02:00
host: &dyn crate::Host,
env: &mut crate::Environment,
2019-05-12 00:59:57 +02:00
) -> Result<Box<dyn Command>, ShellError>;
2019-05-11 10:08:21 +02:00
}
2019-05-15 18:12:38 +02:00
#[derive(Debug)]
pub enum CommandAction {
2019-05-11 10:08:21 +02:00
ChangeCwd(PathBuf),
}
2019-05-15 18:12:38 +02:00
#[derive(Debug)]
pub enum ReturnValue {
Value(Value),
Action(CommandAction),
2019-05-11 10:08:21 +02:00
}
impl ReturnValue {
crate fn single(value: Value) -> VecDeque<ReturnValue> {
let mut v = VecDeque::new();
v.push_back(ReturnValue::Value(value));
v
2019-05-11 10:08:21 +02:00
}
crate fn change_cwd(path: PathBuf) -> ReturnValue {
ReturnValue::Action(CommandAction::ChangeCwd(path))
2019-05-11 10:08:21 +02:00
}
2019-05-10 18:59:12 +02:00
}
pub trait Command {
fn run(&mut self, stream: VecDeque<Value>) -> Result<VecDeque<ReturnValue>, ShellError>;
}