use crate::errors::ShellError; use crate::object::Value; use crate::prelude::*; use std::path::PathBuf; pub struct CommandArgs { pub host: Arc>, pub env: Arc>, pub args: Vec, pub input: InputStream, } impl CommandArgs { crate fn from_context( ctx: &'caller mut Context, args: Vec, input: InputStream, ) -> CommandArgs { CommandArgs { host: ctx.host.clone(), env: ctx.env.clone(), args, input, } } } #[derive(Debug)] pub enum CommandAction { ChangeCwd(PathBuf), } #[derive(Debug)] pub enum ReturnValue { Value(Value), Action(CommandAction), } impl ReturnValue { crate fn change_cwd(path: PathBuf) -> ReturnValue { ReturnValue::Action(CommandAction::ChangeCwd(path)) } } pub trait Command { fn run(&self, args: CommandArgs) -> Result; } impl Command for F where F: Fn(CommandArgs) -> Result, { fn run(&self, args: CommandArgs) -> Result { self(args) } }