diff --git a/src/cli.rs b/src/cli.rs index fe8836a6ae..ae14596ceb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,7 +5,7 @@ use crate::commands::classified::{ }; use crate::commands::plugin::JsonRpc; use crate::commands::plugin::{PluginCommand, PluginSink}; -use crate::commands::static_command; +use crate::commands::whole_stream_command; use crate::context::Context; crate use crate::errors::ShellError; use crate::git::current_branch; @@ -67,14 +67,14 @@ fn load_plugin(path: &std::path::Path, context: &mut Context) -> Result<(), Shel if params.is_filter { let fname = fname.to_string(); let name = params.name.clone(); - context.add_commands(vec![static_command(PluginCommand::new( + context.add_commands(vec![whole_stream_command(PluginCommand::new( name, fname, params, ))]); Ok(()) } else { let fname = fname.to_string(); let name = params.name.clone(); - context.add_commands(vec![static_command(PluginSink::new( + context.add_commands(vec![whole_stream_command(PluginSink::new( name, fname, params, ))]); Ok(()) @@ -178,25 +178,24 @@ pub async fn cli() -> Result<(), Box> { command("to-yaml", Box::new(to_yaml::to_yaml)), command("sort-by", Box::new(sort_by::sort_by)), command("tags", Box::new(tags::tags)), - static_command(Get), - //static_command(Cd), - static_command(Remove), - static_command(Open), + whole_stream_command(Get), + per_item_command(Remove), + per_item_command(Open), per_item_command(Where), - static_command(Config), - static_command(SkipWhile), + whole_stream_command(Config), + whole_stream_command(SkipWhile), per_item_command(Enter), - static_command(Exit), - static_command(Clip), - static_command(Autoview), - static_command(Cpy), - static_command(Date), - static_command(Mkdir), - static_command(Move), - static_command(Save), - static_command(Table), - static_command(VTable), - static_command(Which), + whole_stream_command(Exit), + whole_stream_command(Clip), + whole_stream_command(Autoview), + per_item_command(Cpy), + whole_stream_command(Date), + per_item_command(Mkdir), + per_item_command(Move), + whole_stream_command(Save), + whole_stream_command(Table), + whole_stream_command(VTable), + whole_stream_command(Which), ]); } let _ = load_plugins(&mut context); @@ -356,7 +355,7 @@ async fn process_line(readline: Result, ctx: &mut Context _ => pipeline .commands .push(ClassifiedCommand::Internal(InternalCommand { - command: static_command(autoview::Autoview), + command: whole_stream_command(autoview::Autoview), name_span: Span::unknown(), args: hir::Call::new( Box::new(hir::Expression::synthetic_string("autoview")), diff --git a/src/commands.rs b/src/commands.rs index b04dd3df6a..54f923607c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -58,8 +58,8 @@ crate use autoview::Autoview; //crate use cd::Cd; crate use clip::Clip; crate use command::{ - command, per_item_command, static_command, Command, CommandArgs, PerItemCommand, - RawCommandArgs, StaticCommand, UnevaluatedCallInfo, + command, per_item_command, whole_stream_command, Command, CommandArgs, PerItemCommand, + RawCommandArgs, UnevaluatedCallInfo, WholeStreamCommand, }; crate use config::Config; crate use cp::Cpy; diff --git a/src/commands/autoview.rs b/src/commands/autoview.rs index f1842865ba..88167fa3e5 100644 --- a/src/commands/autoview.rs +++ b/src/commands/autoview.rs @@ -1,4 +1,4 @@ -use crate::commands::{RawCommandArgs, StaticCommand}; +use crate::commands::{RawCommandArgs, WholeStreamCommand}; use crate::errors::ShellError; use crate::prelude::*; @@ -7,7 +7,7 @@ pub struct Autoview; #[derive(Deserialize)] pub struct AutoviewArgs {} -impl StaticCommand for Autoview { +impl WholeStreamCommand for Autoview { fn name(&self) -> &str { "autoview" } diff --git a/src/commands/clip.rs b/src/commands/clip.rs index da88756d3c..f9fbd8d11b 100644 --- a/src/commands/clip.rs +++ b/src/commands/clip.rs @@ -1,4 +1,4 @@ -use crate::commands::{CommandArgs, StaticCommand}; +use crate::commands::{CommandArgs, WholeStreamCommand}; use crate::context::CommandRegistry; use crate::errors::{labelled, ShellError}; use crate::prelude::*; @@ -11,7 +11,7 @@ pub struct Clip; #[derive(Deserialize)] pub struct ClipArgs {} -impl StaticCommand for Clip { +impl WholeStreamCommand for Clip { fn name(&self) -> &str { "clip" } diff --git a/src/commands/command.rs b/src/commands/command.rs index e90cd05cb8..2d06e70af2 100644 --- a/src/commands/command.rs +++ b/src/commands/command.rs @@ -91,13 +91,13 @@ impl CommandArgs { pub fn evaluate_once( self, registry: ®istry::CommandRegistry, - ) -> Result { + ) -> Result { let host = self.host.clone(); let shell_manager = self.shell_manager.clone(); let input = self.input; let call_info = self.call_info.evaluate(registry, &Scope::empty())?; - Ok(EvaluatedStaticCommandArgs::new( + Ok(EvaluatedWholeStreamCommandArgs::new( host, shell_manager, call_info, @@ -217,26 +217,26 @@ impl RunnableRawArgs { } } -pub struct EvaluatedStaticCommandArgs { +pub struct EvaluatedWholeStreamCommandArgs { pub args: EvaluatedCommandArgs, pub input: InputStream, } -impl Deref for EvaluatedStaticCommandArgs { +impl Deref for EvaluatedWholeStreamCommandArgs { type Target = EvaluatedCommandArgs; fn deref(&self) -> &Self::Target { &self.args } } -impl EvaluatedStaticCommandArgs { +impl EvaluatedWholeStreamCommandArgs { pub fn new( host: Arc>, shell_manager: ShellManager, call_info: CallInfo, input: impl Into, - ) -> EvaluatedStaticCommandArgs { - EvaluatedStaticCommandArgs { + ) -> EvaluatedWholeStreamCommandArgs { + EvaluatedWholeStreamCommandArgs { args: EvaluatedCommandArgs { host, shell_manager, @@ -251,13 +251,13 @@ impl EvaluatedStaticCommandArgs { } pub fn parts(self) -> (InputStream, registry::EvaluatedArgs) { - let EvaluatedStaticCommandArgs { args, input } = self; + let EvaluatedWholeStreamCommandArgs { args, input } = self; (input, args.call_info.args) } pub fn split(self) -> (InputStream, EvaluatedCommandArgs) { - let EvaluatedStaticCommandArgs { args, input } = self; + let EvaluatedWholeStreamCommandArgs { args, input } = self; (input, args) } @@ -386,7 +386,7 @@ impl ReturnSuccess { } } -pub trait StaticCommand: Send + Sync { +pub trait WholeStreamCommand: Send + Sync { fn name(&self) -> &str; fn run( @@ -411,8 +411,9 @@ pub trait PerItemCommand: Send + Sync { fn run( &self, - args: RawCommandArgs, - registry: ®istry::CommandRegistry, + call_info: &CallInfo, + registry: &CommandRegistry, + shell_manager: &ShellManager, input: Tagged, ) -> Result, ShellError>; @@ -428,21 +429,21 @@ pub trait PerItemCommand: Send + Sync { } pub enum Command { - Static(Arc), + WholeStream(Arc), PerItem(Arc), } impl Command { pub fn name(&self) -> &str { match self { - Command::Static(command) => command.name(), + Command::WholeStream(command) => command.name(), Command::PerItem(command) => command.name(), } } pub fn signature(&self) -> Signature { match self { - Command::Static(command) => command.signature(), + Command::WholeStream(command) => command.signature(), Command::PerItem(command) => command.signature(), } } @@ -453,7 +454,7 @@ impl Command { registry: ®istry::CommandRegistry, ) -> Result { match self { - Command::Static(command) => command.run(args, registry), + Command::WholeStream(command) => command.run(args, registry), Command::PerItem(command) => self.run_helper(command.clone(), args, registry.clone()), } } @@ -464,15 +465,26 @@ impl Command { args: CommandArgs, registry: CommandRegistry, ) -> Result { + println!("raw_args: {:?}", args.call_info); let raw_args = RawCommandArgs { host: args.host, shell_manager: args.shell_manager, call_info: args.call_info, }; + let out = args .input .values - .map(move |x| command.run(raw_args.clone(), ®istry, x).unwrap()) + .map(move |x| { + let call_info = raw_args + .clone() + .call_info + .evaluate(®istry, &Scope::it_value(x.clone())) + .unwrap(); + command + .run(&call_info, ®istry, &raw_args.shell_manager, x) + .unwrap() + }) .flatten(); Ok(out.to_output_stream()) @@ -485,7 +497,7 @@ pub struct FnFilterCommand { func: fn(EvaluatedFilterCommandArgs) -> Result, } -impl StaticCommand for FnFilterCommand { +impl WholeStreamCommand for FnFilterCommand { fn name(&self) -> &str { &self.name } @@ -542,7 +554,7 @@ pub struct FnRawCommand { >, } -impl StaticCommand for FnRawCommand { +impl WholeStreamCommand for FnRawCommand { fn name(&self) -> &str { &self.name } @@ -564,14 +576,14 @@ pub fn command( + Sync, >, ) -> Arc { - Arc::new(Command::Static(Arc::new(FnRawCommand { + Arc::new(Command::WholeStream(Arc::new(FnRawCommand { name: name.to_string(), func, }))) } -pub fn static_command(command: impl StaticCommand + 'static) -> Arc { - Arc::new(Command::Static(Arc::new(command))) +pub fn whole_stream_command(command: impl WholeStreamCommand + 'static) -> Arc { + Arc::new(Command::WholeStream(Arc::new(command))) } pub fn per_item_command(command: impl PerItemCommand + 'static) -> Arc { @@ -583,7 +595,7 @@ pub fn filter( name: &str, func: fn(EvaluatedFilterCommandArgs) -> Result, ) -> Arc { - Arc::new(Command::Static(Arc::new(FnFilterCommand { + Arc::new(Command::WholeStream(Arc::new(FnFilterCommand { name: name.to_string(), func, }))) diff --git a/src/commands/config.rs b/src/commands/config.rs index f185699aa3..b1400207cc 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::object::{config, Value}; use crate::parser::hir::SyntaxType; @@ -18,7 +18,7 @@ pub struct ConfigArgs { path: Tagged, } -impl StaticCommand for Config { +impl WholeStreamCommand for Config { fn name(&self) -> &str { "config" } diff --git a/src/commands/cp.rs b/src/commands/cp.rs index 17fef68651..9c51f11829 100644 --- a/src/commands/cp.rs +++ b/src/commands/cp.rs @@ -7,13 +7,15 @@ use std::path::PathBuf; pub struct Cpy; -impl StaticCommand for Cpy { +impl PerItemCommand for Cpy { fn run( &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - cp(args, registry) + call_info: &CallInfo, + _registry: &CommandRegistry, + shell_manager: &ShellManager, + _input: Tagged, + ) -> Result, ShellError> { + cp(call_info, shell_manager) } fn name(&self) -> &str { @@ -27,13 +29,16 @@ impl StaticCommand for Cpy { } } -pub fn cp(args: CommandArgs, registry: &CommandRegistry) -> Result { - let mut source = PathBuf::from(args.shell_manager.path()); - let mut destination = PathBuf::from(args.shell_manager.path()); - let name_span = args.call_info.name_span; - let args = args.evaluate_once(registry)?; +pub fn cp( + call_info: &CallInfo, + shell_manager: &ShellManager, +) -> Result, ShellError> { + let mut source = PathBuf::from(shell_manager.path()); + let mut destination = PathBuf::from(shell_manager.path()); + let name_span = call_info.name_span; - match args + match call_info + .args .nth(0) .ok_or_else(|| ShellError::string(&format!("No file or directory specified")))? .as_string()? @@ -44,7 +49,8 @@ pub fn cp(args: CommandArgs, registry: &CommandRegistry) -> Result Result Result Result Result o, @@ -275,10 +281,10 @@ pub fn cp(args: CommandArgs, registry: &CommandRegistry) -> Result, + call_info: &CallInfo, + _registry: ®istry::CommandRegistry, + _shell_manager: &ShellManager, + _input: Tagged, ) -> Result, ShellError> { - let call_info = args - .call_info - .evaluate(registry, &Scope::it_value(input)) - .unwrap(); - match call_info.args.expect_nth(0)? { Tagged { item: Value::Primitive(Primitive::String(location)), diff --git a/src/commands/exit.rs b/src/commands/exit.rs index b695f4506f..ce5f1d19e9 100644 --- a/src/commands/exit.rs +++ b/src/commands/exit.rs @@ -1,11 +1,11 @@ -use crate::commands::command::{CommandAction, StaticCommand}; +use crate::commands::command::{CommandAction, WholeStreamCommand}; use crate::errors::ShellError; use crate::parser::registry::{CommandRegistry, Signature}; use crate::prelude::*; pub struct Exit; -impl StaticCommand for Exit { +impl WholeStreamCommand for Exit { fn run( &self, args: CommandArgs, diff --git a/src/commands/get.rs b/src/commands/get.rs index d0645798c7..7dc079089f 100644 --- a/src/commands/get.rs +++ b/src/commands/get.rs @@ -1,4 +1,4 @@ -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::object::Value; use crate::prelude::*; @@ -10,7 +10,7 @@ pub struct GetArgs { rest: Vec>, } -impl StaticCommand for Get { +impl WholeStreamCommand for Get { fn name(&self) -> &str { "get" } diff --git a/src/commands/mkdir.rs b/src/commands/mkdir.rs index ff62b2823d..69608f64e7 100644 --- a/src/commands/mkdir.rs +++ b/src/commands/mkdir.rs @@ -6,13 +6,15 @@ use std::path::{Path, PathBuf}; pub struct Mkdir; -impl StaticCommand for Mkdir { +impl PerItemCommand for Mkdir { fn run( &self, - args: CommandArgs, + call_info: &CallInfo, registry: &CommandRegistry, - ) -> Result { - mkdir(args, registry) + shell_manager: &ShellManager, + input: Tagged, + ) -> Result, ShellError> { + mkdir(call_info, registry, shell_manager, input) } fn name(&self) -> &str { @@ -24,12 +26,15 @@ impl StaticCommand for Mkdir { } } -pub fn mkdir(args: CommandArgs, registry: &CommandRegistry) -> Result { - let args = args.evaluate_once(registry)?; +pub fn mkdir( + call_info: &CallInfo, + _registry: &CommandRegistry, + shell_manager: &ShellManager, + _input: Tagged, +) -> Result, ShellError> { + let mut full_path = PathBuf::from(shell_manager.path()); - let mut full_path = PathBuf::from(args.shell_manager.path()); - - match &args.nth(0) { + match &call_info.args.nth(0) { Some(Tagged { item: value, .. }) => full_path.push(Path::new(&value.as_string()?)), _ => {} } @@ -38,8 +43,8 @@ pub fn mkdir(args: CommandArgs, registry: &CommandRegistry) -> Result Err(ShellError::labeled_error( reason.to_string(), reason.to_string(), - args.nth(0).unwrap().span(), + call_info.args.nth(0).unwrap().span(), )), - Ok(_) => Ok(OutputStream::empty()), + Ok(_) => Ok(VecDeque::new()), } } diff --git a/src/commands/mv.rs b/src/commands/mv.rs index 2b6c02b48f..54a0192bc4 100644 --- a/src/commands/mv.rs +++ b/src/commands/mv.rs @@ -9,13 +9,15 @@ use crate::utils::FileStructure; pub struct Move; -impl StaticCommand for Move { +impl PerItemCommand for Move { fn run( &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - mv(args, registry) + call_info: &CallInfo, + _registry: &CommandRegistry, + shell_manager: &ShellManager, + _input: Tagged, + ) -> Result, ShellError> { + mv(call_info, shell_manager) } fn name(&self) -> &str { @@ -27,13 +29,16 @@ impl StaticCommand for Move { } } -pub fn mv(args: CommandArgs, registry: &CommandRegistry) -> Result { - let mut source = PathBuf::from(args.shell_manager.path()); - let mut destination = PathBuf::from(args.shell_manager.path()); - let span = args.name_span(); - let args = args.evaluate_once(registry)?; +pub fn mv( + call_info: &CallInfo, + shell_manager: &ShellManager, +) -> Result, ShellError> { + let mut source = PathBuf::from(shell_manager.path()); + let mut destination = PathBuf::from(shell_manager.path()); + let span = call_info.name_span; - match args + match call_info + .args .nth(0) .ok_or_else(|| ShellError::string(&format!("No file or directory specified")))? .as_string()? @@ -44,7 +49,8 @@ pub fn mv(args: CommandArgs, registry: &CommandRegistry) -> Result Result Result Result, - raw: bool, -} - -impl StaticCommand for Open { +impl PerItemCommand for Open { fn name(&self) -> &str { "open" } @@ -30,33 +23,42 @@ impl StaticCommand for Open { fn run( &self, - args: CommandArgs, - registry: ®istry::CommandRegistry, - ) -> Result { - args.process(registry, run)?.run() + call_info: &CallInfo, + _registry: &CommandRegistry, + shell_manager: &ShellManager, + _input: Tagged, + ) -> Result, ShellError> { + run(call_info, shell_manager) } } fn run( - OpenArgs { raw, path }: OpenArgs, - RunnableContext { - shell_manager, - name, - .. - }: RunnableContext, -) -> Result { + call_info: &CallInfo, + shell_manager: &ShellManager, +) -> Result, ShellError> { let cwd = PathBuf::from(shell_manager.path()); let full_path = PathBuf::from(cwd); - let path_str = path.to_str().ok_or(ShellError::type_error( - "Path", - "invalid path".tagged(path.tag()), - ))?; + println!("{:?}", call_info.args.nth(0)); + + let path = match call_info + .args + .nth(0) + .ok_or_else(|| ShellError::string(&format!("No file or directory specified")))? + { + file => file, + }; + + let path_str = path.as_string()?; let (file_extension, contents, contents_tag, span_source) = - fetch(&full_path, path_str, path.span())?; + fetch(&full_path, &path_str, path.span())?; - let file_extension = if raw { None } else { file_extension }; + let file_extension = if call_info.args.has("raw") { + None + } else { + file_extension + }; let mut stream = VecDeque::new(); @@ -70,7 +72,7 @@ fn run( match contents { Value::Primitive(Primitive::String(string)) => { - let value = parse_as_value(file_extension, string, contents_tag, name)?; + let value = parse_as_value(file_extension, string, contents_tag, call_info.name_span)?; match value { Tagged { @@ -88,7 +90,7 @@ fn run( other => stream.push_back(ReturnSuccess::value(other.tagged(contents_tag))), }; - Ok(stream.boxed().to_output_stream()) + Ok(stream) } pub fn fetch( diff --git a/src/commands/plugin.rs b/src/commands/plugin.rs index 41b8a83c65..0b02b40f75 100644 --- a/src/commands/plugin.rs +++ b/src/commands/plugin.rs @@ -1,4 +1,4 @@ -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::parser::registry; use crate::prelude::*; @@ -41,7 +41,7 @@ pub struct PluginCommand { config: registry::Signature, } -impl StaticCommand for PluginCommand { +impl WholeStreamCommand for PluginCommand { fn name(&self) -> &str { &self.name } @@ -239,7 +239,7 @@ pub struct PluginSink { config: registry::Signature, } -impl StaticCommand for PluginSink { +impl WholeStreamCommand for PluginSink { fn name(&self) -> &str { &self.name } diff --git a/src/commands/rm.rs b/src/commands/rm.rs index c50ffd9527..c3a13700d6 100644 --- a/src/commands/rm.rs +++ b/src/commands/rm.rs @@ -1,4 +1,3 @@ -use crate::commands::StaticCommand; use crate::errors::ShellError; use crate::parser::hir::SyntaxType; use crate::prelude::*; @@ -8,13 +7,7 @@ use std::path::PathBuf; pub struct Remove; -#[derive(Deserialize)] -pub struct RemoveArgs { - path: Tagged, - recursive: bool, -} - -impl StaticCommand for Remove { +impl PerItemCommand for Remove { fn name(&self) -> &str { "rm" } @@ -27,20 +20,28 @@ impl StaticCommand for Remove { fn run( &self, - args: CommandArgs, - registry: &CommandRegistry, - ) -> Result { - args.process(registry, rm)?.run() + call_info: &CallInfo, + _registry: &CommandRegistry, + shell_manager: &ShellManager, + _input: Tagged, + ) -> Result, ShellError> { + rm(call_info, shell_manager) } } pub fn rm( - RemoveArgs { path, recursive }: RemoveArgs, - context: RunnableContext, -) -> Result { - let mut full_path = context.cwd(); + call_info: &CallInfo, + shell_manager: &ShellManager, +) -> Result, ShellError> { + let mut full_path = PathBuf::from(shell_manager.path()); - match path.item.to_str().unwrap() { + match call_info + .args + .nth(0) + .ok_or_else(|| ShellError::string(&format!("No file or directory specified")))? + .as_string()? + .as_str() + { "." | ".." => return Err(ShellError::string("\".\" and \"..\" may not be removed")), file => full_path.push(file), } @@ -57,11 +58,11 @@ pub fn rm( match entry { Ok(path) => { if path.is_dir() { - if !recursive { + if !call_info.args.has("recursive") { return Err(ShellError::labeled_error( "is a directory", "is a directory", - context.name, + call_info.name_span, )); } std::fs::remove_dir_all(&path).expect("can not remove directory"); @@ -73,5 +74,5 @@ pub fn rm( } } - Ok(OutputStream::empty()) + Ok(VecDeque::new()) } diff --git a/src/commands/save.rs b/src/commands/save.rs index aa32811b15..b0c809a335 100644 --- a/src/commands/save.rs +++ b/src/commands/save.rs @@ -2,7 +2,7 @@ use crate::commands::to_csv::{to_string as to_csv_to_string, value_to_csv_value} use crate::commands::to_json::value_to_json_value; use crate::commands::to_toml::value_to_toml_value; use crate::commands::to_yaml::value_to_yaml_value; -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::object::Value; use crate::prelude::*; @@ -16,7 +16,7 @@ pub struct SaveArgs { raw: bool, } -impl StaticCommand for Save { +impl WholeStreamCommand for Save { fn name(&self) -> &str { "save" } diff --git a/src/commands/skip_while.rs b/src/commands/skip_while.rs index c04befd553..fac080fa87 100644 --- a/src/commands/skip_while.rs +++ b/src/commands/skip_while.rs @@ -1,4 +1,4 @@ -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::prelude::*; @@ -9,7 +9,7 @@ pub struct SkipWhileArgs { condition: value::Block, } -impl StaticCommand for SkipWhile { +impl WholeStreamCommand for SkipWhile { fn name(&self) -> &str { "skip-while" } diff --git a/src/commands/table.rs b/src/commands/table.rs index f4ea5be680..85d4408653 100644 --- a/src/commands/table.rs +++ b/src/commands/table.rs @@ -1,4 +1,4 @@ -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::format::TableView; use crate::prelude::*; @@ -11,7 +11,7 @@ pub struct TableArgs { full: bool, } -impl StaticCommand for Table { +impl WholeStreamCommand for Table { fn name(&self) -> &str { "table" } diff --git a/src/commands/vtable.rs b/src/commands/vtable.rs index a60a877654..4e26c05efd 100644 --- a/src/commands/vtable.rs +++ b/src/commands/vtable.rs @@ -1,4 +1,4 @@ -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::format::VTableView; use crate::prelude::*; @@ -8,7 +8,7 @@ pub struct VTable; #[derive(Deserialize)] pub struct VTableArgs {} -impl StaticCommand for VTable { +impl WholeStreamCommand for VTable { fn name(&self) -> &str { "vtable" } diff --git a/src/commands/where_.rs b/src/commands/where_.rs index ff16001c44..442f7ecd3c 100644 --- a/src/commands/where_.rs +++ b/src/commands/where_.rs @@ -1,4 +1,4 @@ -use crate::commands::{PerItemCommand, RawCommandArgs}; +use crate::commands::PerItemCommand; use crate::errors::ShellError; use crate::parser::hir::SyntaxType; use crate::parser::registry; @@ -17,16 +17,13 @@ impl PerItemCommand for Where { fn run( &self, - args: RawCommandArgs, - registry: ®istry::CommandRegistry, + call_info: &CallInfo, + _registry: ®istry::CommandRegistry, + _shell_manager: &ShellManager, input: Tagged, ) -> Result, ShellError> { let input_clone = input.clone(); - let call_info = args - .with_input(vec![input]) - .evaluate_once(registry) - .unwrap(); - let condition = &call_info.args.call_info.args.positional.unwrap()[0]; + let condition = call_info.args.expect_nth(0)?; match condition { Tagged { item: Value::Block(block), diff --git a/src/commands/which_.rs b/src/commands/which_.rs index c1db491c85..0ffbc19dba 100644 --- a/src/commands/which_.rs +++ b/src/commands/which_.rs @@ -2,12 +2,12 @@ use crate::errors::ShellError; use crate::object::Value; use crate::prelude::*; -use crate::commands::StaticCommand; +use crate::commands::WholeStreamCommand; use crate::parser::registry::Signature; pub struct Which; -impl StaticCommand for Which { +impl WholeStreamCommand for Which { fn run( &self, args: CommandArgs, diff --git a/src/parser/registry.rs b/src/parser/registry.rs index 8370c0b291..b73007d26f 100644 --- a/src/parser/registry.rs +++ b/src/parser/registry.rs @@ -290,16 +290,18 @@ crate fn evaluate_args( scope: &Scope, source: &Text, ) -> Result { + println!("positional (before): {:?}", call); let positional: Result>, _> = call .positional() .as_ref() .map(|p| { p.iter() - .map(|e| evaluate_baseline_expr(e, &CommandRegistry::empty(), scope, source)) + .map(|e| evaluate_baseline_expr(e, registry, scope, source)) .collect() }) .transpose(); + println!("positional: {:?}", positional); let positional = positional?; let named: Result>>, ShellError> = call diff --git a/src/plugins/sys.rs b/src/plugins/sys.rs index 2f1c2428a3..da7502c6d5 100644 --- a/src/plugins/sys.rs +++ b/src/plugins/sys.rs @@ -17,8 +17,6 @@ impl Sys { } } -//TODO: add more error checking - async fn cpu(tag: Tag) -> Option> { if let (Ok(num_cpu), Ok(cpu_speed)) = ( heim::cpu::logical_count().await, diff --git a/src/prelude.rs b/src/prelude.rs index fe277bdae0..9e1f7322f8 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -34,9 +34,9 @@ macro_rules! trace_stream { crate use crate::cli::MaybeOwned; crate use crate::commands::command::{ - CommandAction, CommandArgs, ReturnSuccess, ReturnValue, RunnableContext, + CallInfo, CommandAction, CommandArgs, ReturnSuccess, ReturnValue, RunnableContext, }; -crate use crate::commands::StaticCommand; +crate use crate::commands::PerItemCommand; crate use crate::context::CommandRegistry; crate use crate::context::{Context, SpanSource}; crate use crate::env::host::handle_unexpected; diff --git a/src/shell/filesystem_shell.rs b/src/shell/filesystem_shell.rs index db1be0a1af..dcaf4f1d20 100644 --- a/src/shell/filesystem_shell.rs +++ b/src/shell/filesystem_shell.rs @@ -1,4 +1,4 @@ -use crate::commands::command::EvaluatedStaticCommandArgs; +use crate::commands::command::EvaluatedWholeStreamCommandArgs; use crate::context::SourceMap; use crate::object::dir_entry_dict; use crate::prelude::*; @@ -60,7 +60,7 @@ impl Shell for FilesystemShell { "filesystem".to_string() } - fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result { + fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let cwd = self.path.clone(); let mut full_path = PathBuf::from(&self.path); match &args.nth(0) { @@ -133,7 +133,7 @@ impl Shell for FilesystemShell { Ok(shell_entries.to_output_stream()) } - fn cd(&self, args: EvaluatedStaticCommandArgs) -> Result { + fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let path = match args.nth(0) { None => match dirs::home_dir() { Some(o) => o, diff --git a/src/shell/shell.rs b/src/shell/shell.rs index 416717c268..bbf60d1cb6 100644 --- a/src/shell/shell.rs +++ b/src/shell/shell.rs @@ -1,12 +1,12 @@ -use crate::commands::command::EvaluatedStaticCommandArgs; +use crate::commands::command::EvaluatedWholeStreamCommandArgs; use crate::context::SourceMap; use crate::errors::ShellError; use crate::stream::OutputStream; pub trait Shell { fn name(&self, source_map: &SourceMap) -> String; - fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result; - fn cd(&self, args: EvaluatedStaticCommandArgs) -> Result; + fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result; + fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result; fn path(&self) -> String; fn set_path(&mut self, path: String); diff --git a/src/shell/shell_manager.rs b/src/shell/shell_manager.rs index 9c05707ba9..0bc7291eac 100644 --- a/src/shell/shell_manager.rs +++ b/src/shell/shell_manager.rs @@ -1,4 +1,4 @@ -use crate::commands::command::EvaluatedStaticCommandArgs; +use crate::commands::command::EvaluatedWholeStreamCommandArgs; use crate::errors::ShellError; use crate::prelude::*; use crate::shell::filesystem_shell::FilesystemShell; @@ -88,12 +88,12 @@ impl ShellManager { self.set_path(self.path()); } - pub fn ls(&self, args: EvaluatedStaticCommandArgs) -> Result { + pub fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let env = self.shells.lock().unwrap(); env.last().unwrap().ls(args) } - pub fn cd(&self, args: EvaluatedStaticCommandArgs) -> Result { + pub fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let env = self.shells.lock().unwrap(); env.last().unwrap().cd(args) diff --git a/src/shell/value_shell.rs b/src/shell/value_shell.rs index d8b267dbc3..6cf4a51769 100644 --- a/src/shell/value_shell.rs +++ b/src/shell/value_shell.rs @@ -1,4 +1,4 @@ -use crate::commands::command::EvaluatedStaticCommandArgs; +use crate::commands::command::EvaluatedWholeStreamCommandArgs; use crate::context::SourceMap; use crate::prelude::*; use crate::shell::shell::Shell; @@ -65,14 +65,14 @@ impl Shell for ValueShell { ) } - fn ls(&self, _args: EvaluatedStaticCommandArgs) -> Result { + fn ls(&self, _args: EvaluatedWholeStreamCommandArgs) -> Result { Ok(self .members() .map(|x| ReturnSuccess::value(x)) .to_output_stream()) } - fn cd(&self, args: EvaluatedStaticCommandArgs) -> Result { + fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { let path = match args.nth(0) { None => "/".to_string(), Some(v) => {