diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 9186d4959c..6984117768 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -513,14 +513,14 @@ fn current_branch() -> String { #[cfg(test)] mod tests { - use nu_engine::basic_evaluation_context; + use nu_engine::EvaluationContext; #[quickcheck] fn quickcheck_parse(data: String) -> bool { let (tokens, err) = nu_parser::lex(&data, 0); let (lite_block, err2) = nu_parser::parse_block(tokens); if err.is_none() && err2.is_none() { - let context = basic_evaluation_context().unwrap(); + let context = EvaluationContext::basic(); let _ = nu_parser::classify_block(&lite_block, &context.scope); } true diff --git a/crates/nu-cli/src/shell/helper.rs b/crates/nu-cli/src/shell/helper.rs index ef1963c9ae..42966041fb 100644 --- a/crates/nu-cli/src/shell/helper.rs +++ b/crates/nu-cli/src/shell/helper.rs @@ -150,7 +150,7 @@ impl rustyline::Helper for Helper {} #[cfg(test)] mod tests { use super::*; - use nu_engine::basic_evaluation_context; + use nu_engine::EvaluationContext; use rustyline::completion::Completer; use rustyline::line_buffer::LineBuffer; @@ -164,7 +164,7 @@ mod tests { buffer.insert_str(0, text); buffer.set_pos(text.len() - 1); - let helper = Helper::new(basic_evaluation_context().unwrap(), None); + let helper = Helper::new(EvaluationContext::basic(), None); helper.update(&mut buffer, "cd ".len(), &replacement); @@ -184,7 +184,7 @@ mod tests { buffer.insert_str(0, text); buffer.set_pos(text.len() - 30); - let helper = Helper::new(basic_evaluation_context().unwrap(), None); + let helper = Helper::new(EvaluationContext::basic(), None); helper.update(&mut buffer, "cd ".len(), &replacement); diff --git a/crates/nu-command/src/commands/all.rs b/crates/nu-command/src/commands/all.rs index 89aa4d0c4d..d570d53197 100644 --- a/crates/nu-command/src/commands/all.rs +++ b/crates/nu-command/src/commands/all.rs @@ -83,7 +83,7 @@ fn all(args: CommandArgs) -> Result { } }; - let scope = args.scope.clone(); + let scope = args.scope(); let init = Ok(InputStream::one( UntaggedValue::boolean(true).into_value(&tag), diff --git a/crates/nu-command/src/commands/any.rs b/crates/nu-command/src/commands/any.rs index c3de50c70a..cecbf9c801 100644 --- a/crates/nu-command/src/commands/any.rs +++ b/crates/nu-command/src/commands/any.rs @@ -83,7 +83,7 @@ fn any(args: CommandArgs) -> Result { } }; - let scope = args.scope.clone(); + let scope = args.scope(); let init = Ok(InputStream::one( UntaggedValue::boolean(false).into_value(&tag), diff --git a/crates/nu-command/src/commands/autoenv.rs b/crates/nu-command/src/commands/autoenv.rs index 4768523855..d8a8b492ae 100644 --- a/crates/nu-command/src/commands/autoenv.rs +++ b/crates/nu-command/src/commands/autoenv.rs @@ -27,7 +27,7 @@ The .nu-env file has the same format as your $HOME/nu/config.toml file. By loadi } fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Autoenv, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Autoenv, args.scope())).into_value(Tag::unknown()), ))) } diff --git a/crates/nu-command/src/commands/autoview/command.rs b/crates/nu-command/src/commands/autoview/command.rs index 76dbb3cb0e..b2fe059f41 100644 --- a/crates/nu-command/src/commands/autoview/command.rs +++ b/crates/nu-command/src/commands/autoview/command.rs @@ -43,14 +43,15 @@ impl WholeStreamCommand for Command { } } -pub fn autoview(context: CommandArgs) -> Result { - let configuration = context.configs.lock().global_config(); +pub fn autoview(args: CommandArgs) -> Result { + let configuration = args.configs().lock().global_config(); + let tag = args.call_info.name_tag.clone(); - let binary = context.scope.get_command("binaryview"); - let text = context.scope.get_command("textview"); - let table = context.scope.get_command("table"); - - let (mut input_stream, context) = context.split(); + let binary = args.scope().get_command("binaryview"); + let text = args.scope().get_command("textview"); + let table = args.scope().get_command("table"); + let context = args.context; + let mut input_stream = args.input; if let Some(x) = input_stream.next() { match input_stream.next() { @@ -62,7 +63,7 @@ pub fn autoview(context: CommandArgs) -> Result { let stream = InputStream::from_stream(xy_stream); if let Some(table) = table { - let command_args = create_default_command_args(&context).with_input(stream); + let command_args = create_default_command_args(&context, stream, tag); let result = table.run(command_args)?; let _ = result.collect::>(); } @@ -74,12 +75,13 @@ pub fn autoview(context: CommandArgs) -> Result { tag: Tag { anchor, span }, } if anchor.is_some() => { if let Some(text) = text { - let mut stream = VecDeque::new(); - stream.push_back( - UntaggedValue::string(s).into_value(Tag { anchor, span }), + let command_args = create_default_command_args( + &context, + InputStream::one( + UntaggedValue::string(s).into_value(Tag { anchor, span }), + ), + tag, ); - let command_args = - create_default_command_args(&context).with_input(stream); let result = text.run_with_actions(command_args)?; let _ = result.collect::>(); } else { @@ -158,10 +160,8 @@ pub fn autoview(context: CommandArgs) -> Result { .. } => { if let Some(binary) = binary { - let mut stream = VecDeque::new(); - stream.push_back(x); let command_args = - create_default_command_args(&context).with_input(stream); + create_default_command_args(&context, InputStream::one(x), tag); let result = binary.run_with_actions(command_args)?; let _ = result.collect::>(); } else { @@ -220,10 +220,8 @@ pub fn autoview(context: CommandArgs) -> Result { println!("{}", nu_table::draw_table(&table, term_width, &color_hm)); } else if let Some(table) = table { - let mut stream = VecDeque::new(); - stream.push_back(x); let command_args = - create_default_command_args(&context).with_input(stream); + create_default_command_args(&context, InputStream::one(x), tag); let result = table.run(command_args)?; let _ = result.collect::>(); } else { @@ -240,10 +238,8 @@ pub fn autoview(context: CommandArgs) -> Result { value: ref item, .. } => { if let Some(table) = table { - let mut stream = VecDeque::new(); - stream.push_back(x); let command_args = - create_default_command_args(&context).with_input(stream); + create_default_command_args(&context, InputStream::one(x), tag); let result = table.run(command_args)?; let _ = result.collect::>(); } else { @@ -258,14 +254,14 @@ pub fn autoview(context: CommandArgs) -> Result { Ok(InputStream::empty()) } -fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawCommandArgs { - let span = context.name.span; - RawCommandArgs { - host: context.host.clone(), - ctrl_c: context.ctrl_c.clone(), - configs: context.configs.clone(), - current_errors: context.current_errors.clone(), - shell_manager: context.shell_manager.clone(), +fn create_default_command_args( + context: &EvaluationContext, + input: InputStream, + tag: Tag, +) -> CommandArgs { + let span = tag.span; + CommandArgs { + context: context.clone(), call_info: UnevaluatedCallInfo { args: hir::Call { head: Box::new(SpannedExpression::new( @@ -277,9 +273,9 @@ fn create_default_command_args(context: &RunnableContextWithoutInput) -> RawComm span, external_redirection: ExternalRedirection::Stdout, }, - name_tag: context.name.clone(), + name_tag: tag, }, - scope: Scope::new(), + input, } } diff --git a/crates/nu-command/src/commands/benchmark.rs b/crates/nu-command/src/commands/benchmark.rs index dcb0c6b21e..2c5e5d1fc8 100644 --- a/crates/nu-command/src/commands/benchmark.rs +++ b/crates/nu-command/src/commands/benchmark.rs @@ -70,11 +70,11 @@ impl WholeStreamCommand for Benchmark { } } -fn benchmark(raw_args: CommandArgs) -> Result { - let tag = raw_args.call_info.args.span; - let mut context = EvaluationContext::from_args(&raw_args); - let scope = raw_args.scope.clone(); - let (BenchmarkArgs { block, passthrough }, input) = raw_args.process()?; +fn benchmark(args: CommandArgs) -> Result { + let tag = args.call_info.args.span; + let mut context = EvaluationContext::from_args(&args); + let scope = args.scope().clone(); + let (BenchmarkArgs { block, passthrough }, input) = args.process()?; let env = scope.get_env_vars(); let name = generate_free_name(&env); diff --git a/crates/nu-command/src/commands/cal.rs b/crates/nu-command/src/commands/cal.rs index fb56c01a25..0e5e2a929a 100644 --- a/crates/nu-command/src/commands/cal.rs +++ b/crates/nu-command/src/commands/cal.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use chrono::{Datelike, Local, NaiveDate}; use indexmap::IndexMap; -use nu_engine::{EvaluatedWholeStreamCommandArgs, WholeStreamCommand}; +use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand}; use nu_errors::ShellError; use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value}; @@ -165,7 +165,7 @@ fn get_current_date() -> (i32, u32, u32) { } fn add_months_of_year_to_table( - args: &EvaluatedWholeStreamCommandArgs, + args: &EvaluatedCommandArgs, mut calendar_vec_deque: &mut VecDeque, tag: &Tag, selected_year: i32, @@ -198,7 +198,7 @@ fn add_months_of_year_to_table( } fn add_month_to_table( - args: &EvaluatedWholeStreamCommandArgs, + args: &EvaluatedCommandArgs, calendar_vec_deque: &mut VecDeque, tag: &Tag, selected_year: i32, diff --git a/crates/nu-command/src/commands/cd.rs b/crates/nu-command/src/commands/cd.rs index 2a7498479d..3c7579ec38 100644 --- a/crates/nu-command/src/commands/cd.rs +++ b/crates/nu-command/src/commands/cd.rs @@ -26,7 +26,7 @@ impl WholeStreamCommand for Cd { fn run_with_actions(&self, args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let (args, _): (CdArgs, _) = args.process()?; shell_manager.cd(args, name) } diff --git a/crates/nu-command/src/commands/chart.rs b/crates/nu-command/src/commands/chart.rs index 8ae14bc123..edc6f59f5b 100644 --- a/crates/nu-command/src/commands/chart.rs +++ b/crates/nu-command/src/commands/chart.rs @@ -20,14 +20,14 @@ impl WholeStreamCommand for Chart { } fn run_with_actions(&self, args: CommandArgs) -> Result { - if args.scope.get_command("chart bar").is_none() { + if args.scope().get_command("chart bar").is_none() { return Err(ShellError::untagged_runtime_error( "nu_plugin_chart not installed.", )); } Ok(ActionStream::one(Ok(ReturnSuccess::Value( - UntaggedValue::string(get_full_help(&Chart, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Chart, args.scope())).into_value(Tag::unknown()), )))) } } diff --git a/crates/nu-command/src/commands/classified/external.rs b/crates/nu-command/src/commands/classified/external.rs index 798de4a225..b0106d1bd8 100644 --- a/crates/nu-command/src/commands/classified/external.rs +++ b/crates/nu-command/src/commands/classified/external.rs @@ -534,7 +534,7 @@ mod tests { use super::{run_external_command, InputStream}; #[cfg(feature = "which")] - use nu_engine::basic_evaluation_context; + use nu_engine::EvaluationContext; #[cfg(feature = "which")] use nu_test_support::commands::ExternalBuilder; @@ -557,8 +557,7 @@ mod tests { let cmd = ExternalBuilder::for_name("i_dont_exist.exe").build(); let input = InputStream::empty(); - let mut ctx = - basic_evaluation_context().expect("There was a problem creating a basic context."); + let mut ctx = EvaluationContext::basic(); assert!(run_external_command(cmd, &mut ctx, input, ExternalRedirection::Stdout).is_err()); } @@ -566,7 +565,7 @@ mod tests { // fn failure_run() -> Result<(), ShellError> { // let cmd = ExternalBuilder::for_name("fail").build(); - // let mut ctx = crate::cli::basic_evaluation_context().expect("There was a problem creating a basic context."); + // let mut ctx = crate::cli::EvaluationContext::basic().expect("There was a problem creating a basic context."); // let stream = run_external_command(cmd, &mut ctx, None, false) // ? // .expect("There was a problem running the external command."); diff --git a/crates/nu-command/src/commands/config/clear.rs b/crates/nu-command/src/commands/config/clear.rs index 3a2b1e44dd..295f48beb8 100644 --- a/crates/nu-command/src/commands/config/clear.rs +++ b/crates/nu-command/src/commands/config/clear.rs @@ -34,7 +34,7 @@ impl WholeStreamCommand for SubCommand { pub fn clear(args: CommandArgs) -> Result { let ctx = EvaluationContext::from_args(&args); - let result = if let Some(global_cfg) = &mut args.configs.lock().global_config { + let result = if let Some(global_cfg) = &mut args.configs().lock().global_config { global_cfg.vars.clear(); global_cfg.write()?; ctx.reload_config(global_cfg)?; diff --git a/crates/nu-command/src/commands/config/command.rs b/crates/nu-command/src/commands/config/command.rs index cf9b4fc4bc..94d65a5c64 100644 --- a/crates/nu-command/src/commands/config/command.rs +++ b/crates/nu-command/src/commands/config/command.rs @@ -21,9 +21,9 @@ impl WholeStreamCommand for Command { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let name = args.call_info.name_tag; + let name = args.call_info.name_tag.clone(); - if let Some(global_cfg) = &args.configs.lock().global_config { + if let Some(global_cfg) = &args.configs().lock().global_config { let result = global_cfg.vars.clone(); Ok(vec![ReturnSuccess::value( UntaggedValue::Row(result.into()).into_value(name), diff --git a/crates/nu-command/src/commands/config/path.rs b/crates/nu-command/src/commands/config/path.rs index 81e6c1aaf5..3a469f6c5f 100644 --- a/crates/nu-command/src/commands/config/path.rs +++ b/crates/nu-command/src/commands/config/path.rs @@ -32,7 +32,7 @@ impl WholeStreamCommand for SubCommand { } pub fn path(args: CommandArgs) -> Result { - if let Some(global_cfg) = &mut args.configs.lock().global_config { + if let Some(global_cfg) = &mut args.configs().lock().global_config { Ok(ActionStream::one(ReturnSuccess::value( UntaggedValue::Primitive(Primitive::FilePath(global_cfg.file_path.clone())), ))) diff --git a/crates/nu-command/src/commands/cp.rs b/crates/nu-command/src/commands/cp.rs index cca025a55d..e67d8eeebb 100644 --- a/crates/nu-command/src/commands/cp.rs +++ b/crates/nu-command/src/commands/cp.rs @@ -26,7 +26,7 @@ impl WholeStreamCommand for Cpy { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let name = args.call_info.name_tag.clone(); let (args, _) = args.process()?; shell_manager.cp(args, name) diff --git a/crates/nu-command/src/commands/date/command.rs b/crates/nu-command/src/commands/date/command.rs index 7fc344f482..3c2193ff3c 100644 --- a/crates/nu-command/src/commands/date/command.rs +++ b/crates/nu-command/src/commands/date/command.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), ))) } } diff --git a/crates/nu-command/src/commands/default_context.rs b/crates/nu-command/src/commands/default_context.rs index d40cb07786..9cc4f15dbc 100644 --- a/crates/nu-command/src/commands/default_context.rs +++ b/crates/nu-command/src/commands/default_context.rs @@ -1,10 +1,9 @@ use crate::prelude::*; -use nu_engine::basic_evaluation_context; use nu_engine::whole_stream_command; use std::error::Error; pub fn create_default_context(interactive: bool) -> Result> { - let context = basic_evaluation_context()?; + let context = EvaluationContext::basic(); { use crate::commands::*; diff --git a/crates/nu-command/src/commands/du.rs b/crates/nu-command/src/commands/du.rs index 0bb541cfa2..f7b12326bb 100644 --- a/crates/nu-command/src/commands/du.rs +++ b/crates/nu-command/src/commands/du.rs @@ -85,7 +85,7 @@ impl WholeStreamCommand for Du { fn du(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let ctrl_c = args.ctrl_c.clone(); + let ctrl_c = args.ctrl_c(); let ctrl_c_copy = ctrl_c.clone(); let (args, _): (DuArgs, _) = args.process()?; diff --git a/crates/nu-command/src/commands/enter.rs b/crates/nu-command/src/commands/enter.rs index c89ed359fe..1b173bf690 100644 --- a/crates/nu-command/src/commands/enter.rs +++ b/crates/nu-command/src/commands/enter.rs @@ -75,16 +75,12 @@ documentation link at https://docs.rs/encoding_rs/0.8.28/encoding_rs/#statics"# } } -fn enter(raw_args: CommandArgs) -> Result { - let scope = raw_args.scope.clone(); - let shell_manager = raw_args.shell_manager.clone(); - let head = raw_args.call_info.args.head.clone(); - let ctrl_c = raw_args.ctrl_c.clone(); - let configs = raw_args.configs.clone(); - let current_errors = raw_args.current_errors.clone(); - let host = raw_args.host.clone(); - let tag = raw_args.call_info.name_tag.clone(); - let (EnterArgs { location, encoding }, _) = raw_args.process()?; +fn enter(args: CommandArgs) -> Result { + let head = args.call_info.args.head.clone(); + let context = args.context.clone(); + let scope = args.scope().clone(); + let path = args.context.shell_manager.path(); + let (EnterArgs { location, encoding }, _) = args.process()?; let location_string = location.display().to_string(); if location.is_dir() { @@ -93,7 +89,7 @@ fn enter(raw_args: CommandArgs) -> Result { ))) } else { // If it's a file, attempt to open the file as a value and enter it - let cwd = shell_manager.path(); + let cwd = path; let full_path = std::path::PathBuf::from(cwd); let span = location.span(); @@ -110,12 +106,9 @@ fn enter(raw_args: CommandArgs) -> Result { if let Some(extension) = file_extension { let command_name = format!("from {}", extension); if let Some(converter) = scope.get_command(&command_name) { - let new_args = RawCommandArgs { - host, - ctrl_c, - configs, - current_errors, - shell_manager, + let tag = tagged_contents.tag.clone(); + let new_args = CommandArgs { + context, call_info: UnevaluatedCallInfo { args: nu_protocol::hir::Call { head, @@ -124,13 +117,11 @@ fn enter(raw_args: CommandArgs) -> Result { span: Span::unknown(), external_redirection: ExternalRedirection::Stdout, }, - name_tag: tag, + name_tag: tag.clone(), }, - scope, + input: InputStream::one(tagged_contents), }; - let tag = tagged_contents.tag.clone(); - let mut result = - converter.run(new_args.with_input(vec![tagged_contents]))?; + let mut result = converter.run(new_args)?; let result_vec: Vec = result.drain_vec(); Ok(result_vec .into_iter() diff --git a/crates/nu-command/src/commands/from.rs b/crates/nu-command/src/commands/from.rs index bb79c48000..5d6d68af9d 100644 --- a/crates/nu-command/src/commands/from.rs +++ b/crates/nu-command/src/commands/from.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for From { fn run(&self, args: CommandArgs) -> Result { Ok(OutputStream::one( - UntaggedValue::string(get_full_help(&From, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&From, args.scope())).into_value(Tag::unknown()), )) } } diff --git a/crates/nu-command/src/commands/hash_/command.rs b/crates/nu-command/src/commands/hash_/command.rs index 8a8d0a0f86..b5c8091c16 100644 --- a/crates/nu-command/src/commands/hash_/command.rs +++ b/crates/nu-command/src/commands/hash_/command.rs @@ -23,7 +23,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), ))) } } diff --git a/crates/nu-command/src/commands/help.rs b/crates/nu-command/src/commands/help.rs index c9e07a287d..eea5dea52e 100644 --- a/crates/nu-command/src/commands/help.rs +++ b/crates/nu-command/src/commands/help.rs @@ -38,7 +38,7 @@ impl WholeStreamCommand for Help { fn help(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let scope = args.scope.clone(); + let scope = args.scope().clone(); let (HelpArgs { rest }, ..) = args.process()?; if !rest.is_empty() { diff --git a/crates/nu-command/src/commands/into/command.rs b/crates/nu-command/src/commands/into/command.rs index b3373a34ed..4e90f0878f 100644 --- a/crates/nu-command/src/commands/into/command.rs +++ b/crates/nu-command/src/commands/into/command.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), ))) } } diff --git a/crates/nu-command/src/commands/ls.rs b/crates/nu-command/src/commands/ls.rs index 2f844a449a..76cd6612c5 100644 --- a/crates/nu-command/src/commands/ls.rs +++ b/crates/nu-command/src/commands/ls.rs @@ -41,8 +41,8 @@ impl WholeStreamCommand for Ls { fn run_with_actions(&self, args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctrl_c = args.ctrl_c.clone(); - let shell_manager = args.shell_manager.clone(); + let ctrl_c = args.ctrl_c(); + let shell_manager = args.shell_manager(); let (args, _) = args.process()?; shell_manager.ls(args, name, ctrl_c) } diff --git a/crates/nu-command/src/commands/macros.rs b/crates/nu-command/src/commands/macros.rs index 844d133df4..cf89796dbe 100644 --- a/crates/nu-command/src/commands/macros.rs +++ b/crates/nu-command/src/commands/macros.rs @@ -1,352 +1,351 @@ -#[doc(hidden)] -#[macro_export] -macro_rules! command { - ( - Named { $export:tt $args:ident $body:block } - Positional { $($number:tt)* } - Rest {} - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $( - ($named_param:tt : $named_type:ty : $named_kind:tt) - )* - } - } +// #[doc(hidden)] +// #[macro_export] +// macro_rules! command { +// ( +// Named { $export:tt $args:ident $body:block } +// Positional { $($number:tt)* } +// Rest {} +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $( +// ($named_param:tt : $named_type:ty : $named_kind:tt) +// )* +// } +// } - Function { - $( ( $param_name:tt : $param_type:tt ) )* - } +// Function { +// $( ( $param_name:tt : $param_type:tt ) )* +// } - Extract { - $($extract:tt)* - } - ) => { - #[allow(non_camel_case_types)] - pub struct $export; +// Extract { +// $($extract:tt)* +// } +// ) => { +// #[allow(non_camel_case_types)] +// pub struct $export; - impl Command for $export { - fn run(&self, $args: CommandArgs) -> Result { - fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result { - let output = $body; +// impl Command for $export { +// fn run(&self, $args: CommandArgs) -> Result { +// fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result { +// let output = $body; - Ok(output.to_action_stream()) - } +// Ok(output.to_action_stream()) +// } - let $args = $args.evaluate_once(registry)?; - let tuple = ( $($extract ,)* ); - command( $args, tuple ) - } +// let $args = $args.evaluate_once(registry)?; +// let tuple = ( $($extract ,)* ); +// command( $args, tuple ) +// } - fn name(&self) -> &str { - stringify!($config_name) - } +// fn name(&self) -> &str { +// stringify!($config_name) +// } - fn config(&self) -> $nu_parser::registry::Signature { - $nu_parser::registry::Signature { - name: self.name().to_string(), - positional: vec![$($mandatory_positional)*], - rest_positional: false, - is_filter: false, - is_sink: false, +// fn config(&self) -> $nu_parser::registry::Signature { +// $nu_parser::registry::Signature { +// name: self.name().to_string(), +// positional: vec![$($mandatory_positional)*], +// rest_positional: false, +// is_filter: false, +// is_sink: false, - named: { - use $nu_parser::registry::NamedType; +// named: { +// use $nu_parser::registry::NamedType; - #[allow(unused_mut)] - let mut named: indexmap::IndexMap = indexmap::IndexMap::new(); +// #[allow(unused_mut)] +// let mut named: indexmap::IndexMap = indexmap::IndexMap::new(); - $( - named.insert(stringify!($named_param).to_string(), $nu_parser::registry::NamedType::$named_kind); - )* +// $( +// named.insert(stringify!($named_param).to_string(), $nu_parser::registry::NamedType::$named_kind); +// )* - named - } - } - } - } - }; +// named +// } +// } +// } +// } +// }; - // switch - ( - Named { $export:tt $args:ident $body:block } - Positional { $($positional_count:tt)* } - Rest { -- $param_name:ident : Switch , $($rest:tt)* } - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $($config_named:tt)* - } - } - Function { - $($function:tt)* - } - Extract { - $($extract:tt)* - } - ) => { - command!( - Named { $export $args $body } - Positional { $($positional_count)* + 1 } - Rest { $($rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![ $($mandatory_positional)* ], - optional_positional: vec![ $($optional_positional)* ], - rest_positional: $rest_positional, - named: { - $($config_named)* - ($param_name : Switch : Switch) - } - } +// // switch +// ( +// Named { $export:tt $args:ident $body:block } +// Positional { $($positional_count:tt)* } +// Rest { -- $param_name:ident : Switch , $($rest:tt)* } +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $($config_named:tt)* +// } +// } +// Function { +// $($function:tt)* +// } +// Extract { +// $($extract:tt)* +// } +// ) => { +// command!( +// Named { $export $args $body } +// Positional { $($positional_count)* + 1 } +// Rest { $($rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![ $($mandatory_positional)* ], +// optional_positional: vec![ $($optional_positional)* ], +// rest_positional: $rest_positional, +// named: { +// $($config_named)* +// ($param_name : Switch : Switch) +// } +// } - Function { - $($function)* ($param_name : Switch) - } +// Function { +// $($function)* ($param_name : Switch) +// } - Extract { - $($extract)* { - use std::convert::TryInto; +// Extract { +// $($extract)* { +// use std::convert::TryInto; - $args.get(stringify!($param_name)).try_into()? - } - } - ); - }; +// $args.get(stringify!($param_name)).try_into()? +// } +// } +// ); +// }; - // mandatory named arguments - ( - Named { $export:tt $args:ident $body:block } - Positional { $($positional_count:tt)* } - Rest { -- $param_name:ident : $param_kind:ty , $($rest:tt)* } - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $($config_named:tt)* - } - } - Function { - $($function:tt)* - } - Extract { - $($extract:tt)* - } - ) => { - command!( - Named { $export $args $body } - Positional { $($positional_count)* + 1 } - Rest { $($rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![ $($mandatory_positional)* ], - optional_positional: vec![ $($optional_positional)* ], - rest_positional: $rest_positional, - named: { - $($config_named)* - ($param_name : Mandatory(NamedValue::Single)) - } - } +// // mandatory named arguments +// ( +// Named { $export:tt $args:ident $body:block } +// Positional { $($positional_count:tt)* } +// Rest { -- $param_name:ident : $param_kind:ty , $($rest:tt)* } +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $($config_named:tt)* +// } +// } +// Function { +// $($function:tt)* +// } +// Extract { +// $($extract:tt)* +// } +// ) => { +// command!( +// Named { $export $args $body } +// Positional { $($positional_count)* + 1 } +// Rest { $($rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![ $($mandatory_positional)* ], +// optional_positional: vec![ $($optional_positional)* ], +// rest_positional: $rest_positional, +// named: { +// $($config_named)* +// ($param_name : Mandatory(NamedValue::Single)) +// } +// } - Function { - $($function)* ($param_name : $param_kind) - } +// Function { +// $($function)* ($param_name : $param_kind) +// } - Extract { - $($extract)* { - use std::convert::TryInto; +// Extract { +// $($extract)* { +// use std::convert::TryInto; - $args.get(stringify!($param_name)).try_into()? - } - } - ); - }; +// $args.get(stringify!($param_name)).try_into()? +// } +// } +// ); +// }; - // optional named arguments - ( - Named { $export:tt $args:ident $body:block } - Positional { $($positional_count:tt)* } - Rest { -- $param_name:ident ? : $param_kind:ty , $($rest:tt)* } - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $($config_named:tt)* - } - } - Function { - $($function:tt)* - } - Extract { - $($extract:tt)* - } - ) => { - command!( - Named { $export $args $body } - Positional { $($positional_count)* + 1 } - Rest { $($rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![ $($mandatory_positional)* ], - optional_positional: vec![ $($optional_positional)* ], - rest_positional: $rest_positional, - named: { - $($config_named)* - ($param_name : Optional(NamedValue::Single)) - } - } +// // optional named arguments +// ( +// Named { $export:tt $args:ident $body:block } +// Positional { $($positional_count:tt)* } +// Rest { -- $param_name:ident ? : $param_kind:ty , $($rest:tt)* } +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $($config_named:tt)* +// } +// } +// Function { +// $($function:tt)* +// } +// Extract { +// $($extract:tt)* +// } +// ) => { +// command!( +// Named { $export $args $body } +// Positional { $($positional_count)* + 1 } +// Rest { $($rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![ $($mandatory_positional)* ], +// optional_positional: vec![ $($optional_positional)* ], +// rest_positional: $rest_positional, +// named: { +// $($config_named)* +// ($param_name : Optional(NamedValue::Single)) +// } +// } - Function { - $($function)* ($param_name : $param_kind) - } +// Function { +// $($function)* ($param_name : $param_kind) +// } - Extract { - $($extract)* { - use std::convert::TryInto; +// Extract { +// $($extract)* { +// use std::convert::TryInto; - $args.get(stringify!($param_name)).try_into()? - } - } - ); - }; +// $args.get(stringify!($param_name)).try_into()? +// } +// } +// ); +// }; - // mandatory positional block - ( - Named { $export:ident $args:ident $body:block } - Positional { $($positional_count:tt)* } - Rest { $param_name:ident : Block , $($rest:tt)* } - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $($config_named:tt)* - } - } +// // mandatory positional block +// ( +// Named { $export:ident $args:ident $body:block } +// Positional { $($positional_count:tt)* } +// Rest { $param_name:ident : Block , $($rest:tt)* } +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $($config_named:tt)* +// } +// } - Function { - $($function:tt)* - } +// Function { +// $($function:tt)* +// } - Extract { - $($extract:tt)* - } +// Extract { +// $($extract:tt)* +// } - ) => { - command!( - Named { $export $args $body } - Positional { $($positional_count)* + 1 } - Rest { $($rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory_block( - stringify!($param_name) - ), ], - optional_positional: vec![ $($optional_positional)* ], - rest_positional: $rest_positional, - named: { - $($config_named)* - } - } +// ) => { +// command!( +// Named { $export $args $body } +// Positional { $($positional_count)* + 1 } +// Rest { $($rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory_block( +// stringify!($param_name) +// ), ], +// optional_positional: vec![ $($optional_positional)* ], +// rest_positional: $rest_positional, +// named: { +// $($config_named)* +// } +// } - Function { - $($function)* ($param_name : Block) - } +// Function { +// $($function)* ($param_name : Block) +// } - Extract { - $($extract:tt)* { - use $nu_data::types::ExtractType; - let value = $args.expect_nth($($positional_count)*)?; - Block::extract(value)? - } - } - ); - }; +// Extract { +// $($extract:tt)* { +// use $nu_data::types::ExtractType; +// let value = $args.expect_nth($($positional_count)*)?; +// Block::extract(value)? +// } +// } +// ); +// }; +// // mandatory positional argument +// ( +// Named { $export:ident $args:ident $body:block } +// Positional { $($positional_count:tt)* } +// Rest { $param_name:ident : $param_kind:ty , $($rest:tt)* } +// Signature { +// name: $config_name:tt, +// mandatory_positional: vec![ $($mandatory_positional:tt)* ], +// optional_positional: vec![ $($optional_positional:tt)* ], +// rest_positional: $rest_positional:tt, +// named: { +// $($config_named:tt)* +// } +// } - // mandatory positional argument - ( - Named { $export:ident $args:ident $body:block } - Positional { $($positional_count:tt)* } - Rest { $param_name:ident : $param_kind:ty , $($rest:tt)* } - Signature { - name: $config_name:tt, - mandatory_positional: vec![ $($mandatory_positional:tt)* ], - optional_positional: vec![ $($optional_positional:tt)* ], - rest_positional: $rest_positional:tt, - named: { - $($config_named:tt)* - } - } +// Function { +// $($function:tt)* +// } - Function { - $($function:tt)* - } +// Extract { +// $($extract:tt)* +// } - Extract { - $($extract:tt)* - } +// ) => { +// command!( +// Named { $export $args $body } +// Positional { $($positional_count)* + 1 } +// Rest { $($rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory( +// stringify!($param_name), <$param_kind>::syntax_type() +// ), ], +// optional_positional: vec![ $($optional_positional)* ], +// rest_positional: $rest_positional, +// named: { +// $($config_named)* +// } +// } - ) => { - command!( - Named { $export $args $body } - Positional { $($positional_count)* + 1 } - Rest { $($rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory( - stringify!($param_name), <$param_kind>::syntax_type() - ), ], - optional_positional: vec![ $($optional_positional)* ], - rest_positional: $rest_positional, - named: { - $($config_named)* - } - } +// Function { +// $($function)* ($param_name : $param_kind) +// } - Function { - $($function)* ($param_name : $param_kind) - } +// Extract { +// $($extract:tt)* { +// use $nu_data::types::ExtractType; +// let value = $args.expect_nth($($positional_count)*)?; +// <$param_kind>::extract(&value)? +// } +// } +// ); +// }; - Extract { - $($extract:tt)* { - use $nu_data::types::ExtractType; - let value = $args.expect_nth($($positional_count)*)?; - <$param_kind>::extract(&value)? - } - } - ); - }; +// ($export:ident as $config_name:tt ( $args:ident , $($command_rest:tt)* ) $body:block) => { +// command!( +// Named { $export $args $body } +// Positional { 0 } +// Rest { $($command_rest)* } +// Signature { +// name: $config_name, +// mandatory_positional: vec![], +// optional_positional: vec![], +// rest_positional: false, +// named: {} +// } - ($export:ident as $config_name:tt ( $args:ident , $($command_rest:tt)* ) $body:block) => { - command!( - Named { $export $args $body } - Positional { 0 } - Rest { $($command_rest)* } - Signature { - name: $config_name, - mandatory_positional: vec![], - optional_positional: vec![], - rest_positional: false, - named: {} - } +// Function { +// } - Function { - } - - Extract { - } - ); - }; -} +// Extract { +// } +// ); +// }; +// } diff --git a/crates/nu-command/src/commands/math/command.rs b/crates/nu-command/src/commands/math/command.rs index dee791ce66..30a83e8fc1 100644 --- a/crates/nu-command/src/commands/math/command.rs +++ b/crates/nu-command/src/commands/math/command.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Command { fn run(&self, args: CommandArgs) -> Result { Ok(OutputStream::one( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), )) } } diff --git a/crates/nu-command/src/commands/mkdir.rs b/crates/nu-command/src/commands/mkdir.rs index 96167ce0ee..166ce5c7f7 100644 --- a/crates/nu-command/src/commands/mkdir.rs +++ b/crates/nu-command/src/commands/mkdir.rs @@ -37,7 +37,7 @@ impl WholeStreamCommand for Mkdir { fn mkdir(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let (args, _) = args.process()?; shell_manager.mkdir(args, name) diff --git a/crates/nu-command/src/commands/move_/mv.rs b/crates/nu-command/src/commands/move_/mv.rs index 17adc9f360..c2dfadb185 100644 --- a/crates/nu-command/src/commands/move_/mv.rs +++ b/crates/nu-command/src/commands/move_/mv.rs @@ -55,7 +55,7 @@ impl WholeStreamCommand for Mv { fn mv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let (args, _) = args.process()?; shell_manager.mv(args, name) diff --git a/crates/nu-command/src/commands/nu/plugin.rs b/crates/nu-command/src/commands/nu/plugin.rs index f74a3e4e4f..1acc8fbaec 100644 --- a/crates/nu-command/src/commands/nu/plugin.rs +++ b/crates/nu-command/src/commands/nu/plugin.rs @@ -46,8 +46,8 @@ impl WholeStreamCommand for SubCommand { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let scope = args.scope.clone(); - let shell_manager = args.shell_manager.clone(); + let scope = args.scope().clone(); + let shell_manager = args.shell_manager(); let (Arguments { load_path }, _) = args.process()?; if let Some(Tagged { diff --git a/crates/nu-command/src/commands/open.rs b/crates/nu-command/src/commands/open.rs index 55d7e17b22..ff28942731 100644 --- a/crates/nu-command/src/commands/open.rs +++ b/crates/nu-command/src/commands/open.rs @@ -100,11 +100,11 @@ pub fn get_encoding(opt: Option>) -> Result<&'static Encoding, Sh } fn open(args: CommandArgs) -> Result { - let scope = args.scope.clone(); - let cwd = PathBuf::from(args.shell_manager.path()); - let shell_manager = args.shell_manager.clone(); + let scope = args.scope().clone(); + let shell_manager = args.shell_manager(); + let cwd = PathBuf::from(shell_manager.path()); let name = args.call_info.name_tag.clone(); - let ctrl_c = args.ctrl_c.clone(); + let ctrl_c = args.ctrl_c(); let ( OpenArgs { diff --git a/crates/nu-command/src/commands/path/command.rs b/crates/nu-command/src/commands/path/command.rs index 58270691d3..22a0d30eb3 100644 --- a/crates/nu-command/src/commands/path/command.rs +++ b/crates/nu-command/src/commands/path/command.rs @@ -35,7 +35,7 @@ the path literal."# fn run(&self, args: CommandArgs) -> Result { Ok(OutputStream::one( - UntaggedValue::string(get_full_help(&Path, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Path, args.scope())).into_value(Tag::unknown()), )) } } diff --git a/crates/nu-command/src/commands/pwd.rs b/crates/nu-command/src/commands/pwd.rs index f71e3f1cdf..02bec23066 100644 --- a/crates/nu-command/src/commands/pwd.rs +++ b/crates/nu-command/src/commands/pwd.rs @@ -32,7 +32,7 @@ impl WholeStreamCommand for Pwd { } pub fn pwd(args: CommandArgs) -> Result { - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let args = args.evaluate_once()?; shell_manager.pwd(args) diff --git a/crates/nu-command/src/commands/random/command.rs b/crates/nu-command/src/commands/random/command.rs index 9072fec370..e4a5c6087b 100644 --- a/crates/nu-command/src/commands/random/command.rs +++ b/crates/nu-command/src/commands/random/command.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(Ok(ReturnSuccess::Value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), )))) } } diff --git a/crates/nu-command/src/commands/rm.rs b/crates/nu-command/src/commands/rm.rs index cdf4fef715..28e4df9a88 100644 --- a/crates/nu-command/src/commands/rm.rs +++ b/crates/nu-command/src/commands/rm.rs @@ -64,7 +64,7 @@ impl WholeStreamCommand for Remove { fn rm(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let shell_manager = args.shell_manager.clone(); + let shell_manager = args.shell_manager(); let (args, _): (RemoveArgs, _) = args.process()?; if args.trash.item && args.permanent.item { diff --git a/crates/nu-command/src/commands/run_external.rs b/crates/nu-command/src/commands/run_external.rs index 3814e0e1ad..8adcde2af6 100644 --- a/crates/nu-command/src/commands/run_external.rs +++ b/crates/nu-command/src/commands/run_external.rs @@ -2,7 +2,6 @@ use crate::commands::classified::external; use crate::prelude::*; use derive_new::new; -use parking_lot::Mutex; use std::path::PathBuf; use nu_engine::shell::CdArgs; @@ -75,17 +74,7 @@ impl WholeStreamCommand for RunExternalCommand { }) .and_then(spanned_expression_to_string)?; - let mut external_context = { - EvaluationContext { - scope: args.scope.clone(), - host: args.host.clone(), - shell_manager: args.shell_manager.clone(), - ctrl_c: args.ctrl_c.clone(), - configs: args.configs.clone(), - current_errors: Arc::new(Mutex::new(vec![])), - windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())), - } - }; + let mut external_context = args.context.clone(); let is_interactive = self.interactive; @@ -111,7 +100,7 @@ impl WholeStreamCommand for RunExternalCommand { let result = external_context .shell_manager - .cd(cd_args, args.call_info.name_tag.clone()); + .cd(cd_args, args.call_info.name_tag); return Ok(result?.to_action_stream()); } diff --git a/crates/nu-command/src/commands/save.rs b/crates/nu-command/src/commands/save.rs index 52fe20ba93..ae6839c96b 100644 --- a/crates/nu-command/src/commands/save.rs +++ b/crates/nu-command/src/commands/save.rs @@ -153,19 +153,16 @@ impl WholeStreamCommand for Save { } } -fn save(raw_args: CommandArgs) -> Result { - let mut full_path = PathBuf::from(raw_args.shell_manager.path()); - let name_tag = raw_args.call_info.name_tag.clone(); - let name = raw_args.call_info.name_tag.clone(); - let scope = raw_args.scope.clone(); - let host = raw_args.host.clone(); - let ctrl_c = raw_args.ctrl_c.clone(); - let configs = raw_args.configs.clone(); - let current_errors = raw_args.current_errors.clone(); - let shell_manager = raw_args.shell_manager.clone(); +fn save(args: CommandArgs) -> Result { + let shell_manager = args.shell_manager(); + let mut full_path = PathBuf::from(shell_manager.path()); + let name_tag = args.call_info.name_tag.clone(); + let name = args.call_info.name_tag.clone(); + let context = args.context.clone(); + let scope = args.scope().clone(); - let head = raw_args.call_info.args.head.clone(); - let args = raw_args.evaluate_once()?; + let head = args.call_info.args.head.clone(); + let args = args.evaluate_once()?; let path: Option> = args.opt(0)?; let save_raw = args.has_flag("raw"); @@ -203,12 +200,8 @@ fn save(raw_args: CommandArgs) -> Result { if let Some(extension) = full_path.extension() { let command_name = format!("to {}", extension.to_string_lossy()); if let Some(converter) = scope.get_command(&command_name) { - let new_args = RawCommandArgs { - host, - ctrl_c, - configs, - current_errors, - shell_manager: shell_manager.clone(), + let new_args = CommandArgs { + context, call_info: UnevaluatedCallInfo { args: nu_protocol::hir::Call { head, @@ -219,9 +212,9 @@ fn save(raw_args: CommandArgs) -> Result { }, name_tag: name_tag.clone(), }, - scope, + input: InputStream::from_stream(input.into_iter()), }; - let mut result = converter.run(new_args.with_input(input))?; + let mut result = converter.run(new_args)?; let result_vec: Vec = result.drain_vec(); if converter.is_binary() { process_binary_return_success!('scope, result_vec, name_tag) diff --git a/crates/nu-command/src/commands/shells.rs b/crates/nu-command/src/commands/shells.rs index 207fc01e47..8f44416f05 100644 --- a/crates/nu-command/src/commands/shells.rs +++ b/crates/nu-command/src/commands/shells.rs @@ -26,12 +26,14 @@ impl WholeStreamCommand for Shells { fn shells(args: CommandArgs) -> ActionStream { let mut shells_out = VecDeque::new(); + let shell_manager = args.shell_manager(); let tag = args.call_info.name_tag; + let active_index = shell_manager.current_shell.load(Ordering::SeqCst); - for (index, shell) in args.shell_manager.shells.lock().iter().enumerate() { + for (index, shell) in shell_manager.shells.lock().iter().enumerate() { let mut dict = TaggedDictBuilder::new(&tag); - if index == (*args.shell_manager.current_shell).load(Ordering::SeqCst) { + if index == active_index { dict.insert_untagged("active", true); } else { dict.insert_untagged("active", false); diff --git a/crates/nu-command/src/commands/sleep.rs b/crates/nu-command/src/commands/sleep.rs index 10b44658b7..c53b17ca03 100644 --- a/crates/nu-command/src/commands/sleep.rs +++ b/crates/nu-command/src/commands/sleep.rs @@ -35,7 +35,7 @@ impl WholeStreamCommand for Sleep { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let ctrl_c = args.ctrl_c().clone(); + let ctrl_c = args.ctrl_c(); let (SleepArgs { duration, rest }, _) = args.process()?; diff --git a/crates/nu-command/src/commands/split/command.rs b/crates/nu-command/src/commands/split/command.rs index f4823c710f..2e9955326a 100644 --- a/crates/nu-command/src/commands/split/command.rs +++ b/crates/nu-command/src/commands/split/command.rs @@ -21,7 +21,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(Ok(ReturnSuccess::Value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), )))) } } diff --git a/crates/nu-command/src/commands/str_/command.rs b/crates/nu-command/src/commands/str_/command.rs index fbafae06ec..be0bbd6382 100644 --- a/crates/nu-command/src/commands/str_/command.rs +++ b/crates/nu-command/src/commands/str_/command.rs @@ -23,7 +23,7 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Command, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Command, args.scope())).into_value(Tag::unknown()), ))) } } diff --git a/crates/nu-command/src/commands/table/command.rs b/crates/nu-command/src/commands/table/command.rs index a9401e9565..07554ec78e 100644 --- a/crates/nu-command/src/commands/table/command.rs +++ b/crates/nu-command/src/commands/table/command.rs @@ -173,7 +173,7 @@ fn values_to_entries( fn table(args: CommandArgs) -> Result { let mut args = args.evaluate_once()?; - let configuration = args.configs.lock().global_config(); + let configuration = args.configs().lock().global_config(); // Ideally, get_color_config would get all the colors configured in the config.toml // and create a style based on those settings. However, there are few places where @@ -191,7 +191,7 @@ fn table(args: CommandArgs) -> Result { let mut delay_slot = None; - let term_width = args.host.lock().width(); + let term_width = args.host().lock().width(); #[cfg(feature = "table-pager")] let pager = Pager::new() diff --git a/crates/nu-command/src/commands/to.rs b/crates/nu-command/src/commands/to.rs index 5f04729819..75573f0984 100644 --- a/crates/nu-command/src/commands/to.rs +++ b/crates/nu-command/src/commands/to.rs @@ -21,7 +21,7 @@ impl WholeStreamCommand for To { fn run(&self, args: CommandArgs) -> Result { Ok(OutputStream::one( - UntaggedValue::string(get_full_help(&To, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&To, args.scope())).into_value(Tag::unknown()), )) } } diff --git a/crates/nu-command/src/commands/url_/command.rs b/crates/nu-command/src/commands/url_/command.rs index f8244993d2..1755feca65 100644 --- a/crates/nu-command/src/commands/url_/command.rs +++ b/crates/nu-command/src/commands/url_/command.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Url { fn run_with_actions(&self, args: CommandArgs) -> Result { Ok(ActionStream::one(ReturnSuccess::value( - UntaggedValue::string(get_full_help(&Url, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&Url, args.scope())).into_value(Tag::unknown()), ))) } } diff --git a/crates/nu-command/src/commands/which_.rs b/crates/nu-command/src/commands/which_.rs index ebb3c9aff9..fe0ee45a40 100644 --- a/crates/nu-command/src/commands/which_.rs +++ b/crates/nu-command/src/commands/which_.rs @@ -220,7 +220,7 @@ fn which(args: CommandArgs) -> Result { let mut output = vec![]; for app in which_args.applications { - let values = which_single(app, which_args.all, &args.scope); + let values = which_single(app, which_args.all, &args.scope()); output.extend(values); } diff --git a/crates/nu-command/src/examples.rs b/crates/nu-command/src/examples.rs index 7c518f6b02..e59f5a8154 100644 --- a/crates/nu-command/src/examples.rs +++ b/crates/nu-command/src/examples.rs @@ -8,7 +8,6 @@ use double_echo::Command as DoubleEcho; use double_ls::Command as DoubleLs; use stub_generate::{mock_path, Command as StubOpen}; -use nu_engine::basic_evaluation_context; use nu_errors::ShellError; use nu_parser::ParserScope; use nu_protocol::hir::{ClassifiedBlock, ExternalRedirection}; @@ -25,7 +24,7 @@ use nu_stream::InputStream; pub fn test_examples(cmd: Command) -> Result<(), ShellError> { let examples = cmd.examples(); - let base_context = basic_evaluation_context()?; + let base_context = EvaluationContext::basic(); base_context.add_commands(vec![ // Command Doubles @@ -91,7 +90,7 @@ pub fn test_examples(cmd: Command) -> Result<(), ShellError> { pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> { let examples = cmd.examples(); - let base_context = basic_evaluation_context()?; + let base_context = EvaluationContext::basic(); base_context.add_commands(vec![ whole_stream_command(Math), @@ -150,7 +149,7 @@ pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> { pub fn test_anchors(cmd: Command) -> Result<(), ShellError> { let examples = cmd.examples(); - let base_context = basic_evaluation_context()?; + let base_context = EvaluationContext::basic(); base_context.add_commands(vec![ // Minimal restricted commands to aid in testing diff --git a/crates/nu-command/src/prelude.rs b/crates/nu-command/src/prelude.rs index a4c2b54176..4b073599d4 100644 --- a/crates/nu-command/src/prelude.rs +++ b/crates/nu-command/src/prelude.rs @@ -16,9 +16,8 @@ pub(crate) use nu_data::value; pub(crate) use nu_engine::EvaluationContext; pub(crate) use nu_engine::Example; pub(crate) use nu_engine::Host; -pub(crate) use nu_engine::RawCommandArgs; +pub(crate) use nu_engine::RunnableContext; pub(crate) use nu_engine::{get_full_help, CommandArgs, Scope, WholeStreamCommand}; -pub(crate) use nu_engine::{RunnableContext, RunnableContextWithoutInput}; pub(crate) use nu_parser::ParserScope; pub(crate) use nu_protocol::{out, row}; pub(crate) use nu_source::{AnchorLocation, PrettyDebug, Span, SpannedItem, Tag, TaggedItem}; diff --git a/crates/nu-engine/src/basic_evaluation_context.rs b/crates/nu-engine/src/basic_evaluation_context.rs deleted file mode 100644 index 133bda09c6..0000000000 --- a/crates/nu-engine/src/basic_evaluation_context.rs +++ /dev/null @@ -1,26 +0,0 @@ -use crate::EvaluationContext; -use crate::Scope; -use crate::{basic_shell_manager, config_holder::ConfigHolder}; -use crate::{env::basic_host::BasicHost, Host}; -use indexmap::IndexMap; -use parking_lot::Mutex; -use std::error::Error; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; - -pub fn basic_evaluation_context() -> Result> { - let scope = Scope::new(); - let mut host = BasicHost {}; - let env_vars = host.vars().iter().cloned().collect::>(); - scope.add_env(env_vars); - - Ok(EvaluationContext { - scope, - host: Arc::new(parking_lot::Mutex::new(Box::new(host))), - current_errors: Arc::new(Mutex::new(vec![])), - ctrl_c: Arc::new(AtomicBool::new(false)), - configs: Arc::new(Mutex::new(ConfigHolder::new())), - shell_manager: basic_shell_manager::basic_shell_manager()?, - windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())), - }) -} diff --git a/crates/nu-engine/src/basic_shell_manager.rs b/crates/nu-engine/src/basic_shell_manager.rs deleted file mode 100644 index c0257b2df6..0000000000 --- a/crates/nu-engine/src/basic_shell_manager.rs +++ /dev/null @@ -1,16 +0,0 @@ -use crate::filesystem::filesystem_shell::{FilesystemShell, FilesystemShellMode}; -use crate::shell::shell_manager::ShellManager; - -use parking_lot::Mutex; -use std::error::Error; -use std::sync::atomic::AtomicUsize; -use std::sync::Arc; - -pub fn basic_shell_manager() -> Result> { - Ok(ShellManager { - current_shell: Arc::new(AtomicUsize::new(0)), - shells: Arc::new(Mutex::new(vec![Box::new(FilesystemShell::basic( - FilesystemShellMode::Cli, - )?)])), - }) -} diff --git a/crates/nu-engine/src/command_args.rs b/crates/nu-engine/src/command_args.rs index ce70bfc3e8..80af8dcdb0 100644 --- a/crates/nu-engine/src/command_args.rs +++ b/crates/nu-engine/src/command_args.rs @@ -21,72 +21,39 @@ use std::sync::Arc; #[derive(Getters)] #[get = "pub"] pub struct CommandArgs { - pub host: Arc>>, - pub ctrl_c: Arc, - pub configs: Arc>, - pub current_errors: Arc>>, - pub shell_manager: ShellManager, + pub context: EvaluationContext, pub call_info: UnevaluatedCallInfo, - pub scope: Scope, pub input: InputStream, } +impl CommandArgs { + pub fn scope(&self) -> &Scope { + &self.context.scope + } + + pub fn host(&self) -> Arc>> { + self.context.host.clone() + } + + pub fn current_errors(&self) -> Arc>> { + self.context.current_errors.clone() + } + + pub fn ctrl_c(&self) -> Arc { + self.context.ctrl_c.clone() + } + + pub fn configs(&self) -> Arc> { + self.context.configs.clone() + } + + pub fn shell_manager(&self) -> ShellManager { + self.context.shell_manager.clone() + } +} + pub type RunnableContext = CommandArgs; -#[derive(Clone)] -pub struct RunnableContextWithoutInput { - pub shell_manager: ShellManager, - pub host: Arc>>, - pub current_errors: Arc>>, - pub ctrl_c: Arc, - pub call_info: UnevaluatedCallInfo, - pub configs: Arc>, - pub scope: Scope, - pub name: Tag, -} - -impl RunnableContextWithoutInput { - pub fn with_input(self, input: InputStream) -> CommandArgs { - CommandArgs { - shell_manager: self.shell_manager, - host: self.host, - current_errors: self.current_errors, - ctrl_c: self.ctrl_c, - call_info: self.call_info, - configs: self.configs, - scope: self.scope, - input, - } - } -} - -#[derive(Getters, Clone)] -#[get = "pub"] -pub struct RawCommandArgs { - pub host: Arc>>, - pub ctrl_c: Arc, - pub current_errors: Arc>>, - pub configs: Arc>, - pub shell_manager: ShellManager, - pub scope: Scope, - pub call_info: UnevaluatedCallInfo, -} - -impl RawCommandArgs { - pub fn with_input(self, input: impl Into) -> CommandArgs { - CommandArgs { - host: self.host, - ctrl_c: self.ctrl_c, - configs: self.configs, - current_errors: self.current_errors, - shell_manager: self.shell_manager, - call_info: self.call_info, - scope: self.scope, - input: input.into(), - } - } -} - impl std::fmt::Debug for CommandArgs { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.call_info.fmt(f) @@ -94,49 +61,18 @@ impl std::fmt::Debug for CommandArgs { } impl CommandArgs { - pub fn evaluate_once(self) -> Result { - let ctx = EvaluationContext::new( - self.scope, - self.host, - self.current_errors, - self.ctrl_c, - self.configs, - self.shell_manager, - Arc::new(Mutex::new(std::collections::HashMap::new())), - ); + pub fn evaluate_once(self) -> Result { + let ctx = self.context.clone(); let input = self.input; let call_info = self.call_info.evaluate(&ctx)?; - Ok(EvaluatedWholeStreamCommandArgs::new( - ctx.host, - ctx.ctrl_c, - ctx.configs, - ctx.shell_manager, - call_info, - input, - ctx.scope, - )) - } - - pub fn split(self) -> (InputStream, RunnableContextWithoutInput) { - let new_context = RunnableContextWithoutInput { - shell_manager: self.shell_manager, - host: self.host, - ctrl_c: self.ctrl_c, - configs: self.configs, - name: self.call_info.name_tag.clone(), - call_info: self.call_info, - current_errors: self.current_errors, - scope: self.scope, - }; - - (self.input, new_context) + Ok(EvaluatedCommandArgs::new(ctx, call_info, input)) } pub fn extract( self, - f: impl FnOnce(&EvaluatedCommandArgs) -> Result, + f: impl FnOnce(&EvaluatedCommandArgsWithoutInput) -> Result, ) -> Result<(T, InputStream), ShellError> { let evaluated_args = self.evaluate_once()?; @@ -153,37 +89,26 @@ impl CommandArgs { } } -pub struct EvaluatedWholeStreamCommandArgs { - pub args: EvaluatedCommandArgs, +pub struct EvaluatedCommandArgs { + pub args: EvaluatedCommandArgsWithoutInput, pub input: InputStream, } -impl Deref for EvaluatedWholeStreamCommandArgs { - type Target = EvaluatedCommandArgs; +impl Deref for EvaluatedCommandArgs { + type Target = EvaluatedCommandArgsWithoutInput; fn deref(&self) -> &Self::Target { &self.args } } -impl EvaluatedWholeStreamCommandArgs { +impl EvaluatedCommandArgs { pub fn new( - host: Arc>, - ctrl_c: Arc, - configs: Arc>, - shell_manager: ShellManager, + context: EvaluationContext, call_info: CallInfo, input: impl Into, - scope: Scope, - ) -> EvaluatedWholeStreamCommandArgs { - EvaluatedWholeStreamCommandArgs { - args: EvaluatedCommandArgs { - host, - ctrl_c, - configs, - shell_manager, - call_info, - scope, - }, + ) -> EvaluatedCommandArgs { + EvaluatedCommandArgs { + args: EvaluatedCommandArgsWithoutInput { context, call_info }, input: input.into(), } } @@ -193,13 +118,13 @@ impl EvaluatedWholeStreamCommandArgs { } pub fn parts(self) -> (InputStream, EvaluatedArgs) { - let EvaluatedWholeStreamCommandArgs { args, input } = self; + let EvaluatedCommandArgs { args, input } = self; (input, args.call_info.args) } - pub fn split(self) -> (InputStream, EvaluatedCommandArgs) { - let EvaluatedWholeStreamCommandArgs { args, input } = self; + pub fn split(self) -> (InputStream, EvaluatedCommandArgsWithoutInput) { + let EvaluatedCommandArgs { args, input } = self; (input, args) } @@ -207,20 +132,28 @@ impl EvaluatedWholeStreamCommandArgs { #[derive(Getters, new)] #[get = "pub(crate)"] -pub struct EvaluatedCommandArgs { - pub host: Arc>, - pub ctrl_c: Arc, - pub configs: Arc>, - pub shell_manager: ShellManager, +pub struct EvaluatedCommandArgsWithoutInput { + pub context: EvaluationContext, pub call_info: CallInfo, - pub scope: Scope, } -impl EvaluatedCommandArgs { +impl EvaluatedCommandArgsWithoutInput { pub fn nth(&self, pos: usize) -> Option<&Value> { self.call_info.args.nth(pos) } + pub fn scope(&self) -> Scope { + self.context.scope.clone() + } + + pub fn configs(&self) -> Arc> { + self.context.configs.clone() + } + + pub fn host(&self) -> Arc>> { + self.context.host.clone() + } + /// Get the nth positional argument, error if not possible pub fn expect_nth(&self, pos: usize) -> Result<&Value, ShellError> { self.call_info diff --git a/crates/nu-engine/src/evaluate/internal.rs b/crates/nu-engine/src/evaluate/internal.rs index f67773bd1d..f1e050c57b 100644 --- a/crates/nu-engine/src/evaluate/internal.rs +++ b/crates/nu-engine/src/evaluate/internal.rs @@ -1,8 +1,8 @@ use crate::call_info::UnevaluatedCallInfo; -use crate::command_args::RawCommandArgs; use crate::evaluation_context::EvaluationContext; use crate::filesystem::filesystem_shell::{FilesystemShell, FilesystemShellMode}; use crate::shell::value_shell::ValueShell; +use crate::CommandArgs; use log::{log_enabled, trace}; use nu_errors::ShellError; use nu_protocol::hir::{ @@ -90,12 +90,8 @@ impl Iterator for InternalIterator { let contents_tag = tagged_contents.tag.clone(); let command_name = format!("from {}", extension); if let Some(converter) = self.context.scope.get_command(&command_name) { - let new_args = RawCommandArgs { - host: self.context.host.clone(), - ctrl_c: self.context.ctrl_c.clone(), - configs: self.context.configs.clone(), - current_errors: self.context.current_errors.clone(), - shell_manager: self.context.shell_manager.clone(), + let new_args = CommandArgs { + context: self.context.clone(), call_info: UnevaluatedCallInfo { args: nu_protocol::hir::Call { head: Box::new(SpannedExpression { @@ -111,9 +107,9 @@ impl Iterator for InternalIterator { }, name_tag: tagged_contents.tag(), }, - scope: self.context.scope.clone(), + input: InputStream::one(tagged_contents), }; - let result = converter.run(new_args.with_input(vec![tagged_contents])); + let result = converter.run(new_args); match result { Ok(mut result) => { diff --git a/crates/nu-engine/src/evaluation_context.rs b/crates/nu-engine/src/evaluation_context.rs index e45cdba50e..e98e32b4d5 100644 --- a/crates/nu-engine/src/evaluation_context.rs +++ b/crates/nu-engine/src/evaluation_context.rs @@ -1,9 +1,10 @@ -use crate::env::host::Host; use crate::evaluate::scope::{Scope, ScopeFrame}; use crate::shell::shell_manager::ShellManager; use crate::whole_stream_command::Command; use crate::{call_info::UnevaluatedCallInfo, config_holder::ConfigHolder}; use crate::{command_args::CommandArgs, script}; +use crate::{env::basic_host::BasicHost, Host}; +use indexmap::IndexMap; use log::trace; use nu_data::config::{self, Conf, NuConfig}; use nu_errors::ShellError; @@ -48,18 +49,27 @@ impl EvaluationContext { } } - pub fn from_args(args: &CommandArgs) -> EvaluationContext { + pub fn basic() -> EvaluationContext { + let scope = Scope::new(); + let mut host = BasicHost {}; + let env_vars = host.vars().iter().cloned().collect::>(); + scope.add_env(env_vars); + EvaluationContext { - scope: args.scope.clone(), - host: args.host.clone(), - current_errors: args.current_errors.clone(), - ctrl_c: args.ctrl_c.clone(), - configs: args.configs.clone(), - shell_manager: args.shell_manager.clone(), + scope, + host: Arc::new(parking_lot::Mutex::new(Box::new(host))), + current_errors: Arc::new(Mutex::new(vec![])), + ctrl_c: Arc::new(AtomicBool::new(false)), + configs: Arc::new(Mutex::new(ConfigHolder::new())), + shell_manager: ShellManager::basic(), windows_drives_previous_cwd: Arc::new(Mutex::new(std::collections::HashMap::new())), } } + pub fn from_args(args: &CommandArgs) -> EvaluationContext { + args.context.clone() + } + pub fn error(&self, error: ShellError) { self.with_errors(|errors| errors.push(error)) } @@ -135,13 +145,8 @@ impl EvaluationContext { fn command_args(&self, args: hir::Call, input: InputStream, name_tag: Tag) -> CommandArgs { CommandArgs { - host: self.host.clone(), - ctrl_c: self.ctrl_c.clone(), - configs: self.configs.clone(), - current_errors: self.current_errors.clone(), - shell_manager: self.shell_manager.clone(), + context: self.clone(), call_info: self.call_info(args, name_tag), - scope: self.scope.clone(), input, } } diff --git a/crates/nu-engine/src/filesystem/filesystem_shell.rs b/crates/nu-engine/src/filesystem/filesystem_shell.rs index 101316f10c..98697b4bf6 100644 --- a/crates/nu-engine/src/filesystem/filesystem_shell.rs +++ b/crates/nu-engine/src/filesystem/filesystem_shell.rs @@ -4,14 +4,14 @@ use crate::filesystem::utils::FileStructure; use crate::maybe_text_codec::{MaybeTextCodec, StringOrBinary}; use crate::shell::shell_args::{CdArgs, CopyArgs, LsArgs, MkdirArgs, MvArgs, RemoveArgs}; use crate::shell::Shell; -use crate::{command_args::EvaluatedWholeStreamCommandArgs, BufCodecReader}; +use crate::{command_args::EvaluatedCommandArgs, BufCodecReader}; use encoding_rs::Encoding; use nu_data::config::LocalConfigDiff; use nu_protocol::{CommandAction, ConfigPath, TaggedDictBuilder, Value}; use nu_source::{Span, Tag}; use nu_stream::{ActionStream, Interruptible, OutputStream, ToActionStream}; use std::collections::VecDeque; -use std::io::{Error, ErrorKind}; +use std::io::ErrorKind; use std::path::{Path, PathBuf}; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -57,17 +57,17 @@ impl FilesystemShell { matches!(&self.mode, FilesystemShellMode::Cli) } - pub fn basic(mode: FilesystemShellMode) -> Result { + pub fn basic(mode: FilesystemShellMode) -> FilesystemShell { let path = match std::env::current_dir() { Ok(path) => path, Err(_) => PathBuf::from("/"), }; - Ok(FilesystemShell { + FilesystemShell { path: path.to_string_lossy().to_string(), last_path: path.to_string_lossy().to_string(), mode, - }) + } } pub fn with_location( @@ -713,6 +713,7 @@ impl Shell for FilesystemShell { let result; #[cfg(feature = "trash-support")] { + use std::io::Error; result = if _trash.item || (rm_always_trash && !_permanent.item) { trash::delete(&f).map_err(|e: trash::Error| { Error::new(ErrorKind::Other, format!("{:?}", e)) @@ -765,7 +766,7 @@ impl Shell for FilesystemShell { self.path.clone() } - fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { + fn pwd(&self, args: EvaluatedCommandArgs) -> Result { let path = PathBuf::from(self.path()); let p = match dunce::canonicalize(path.as_path()) { Ok(p) => p, diff --git a/crates/nu-engine/src/lib.rs b/crates/nu-engine/src/lib.rs index 0ec3a07a2b..cf07e8f642 100644 --- a/crates/nu-engine/src/lib.rs +++ b/crates/nu-engine/src/lib.rs @@ -1,5 +1,3 @@ -pub mod basic_evaluation_context; -pub mod basic_shell_manager; mod call_info; mod command_args; mod config_holder; @@ -18,12 +16,9 @@ pub mod script; pub mod shell; mod whole_stream_command; -pub use crate::basic_evaluation_context::basic_evaluation_context; -pub use crate::basic_shell_manager::basic_shell_manager; pub use crate::call_info::UnevaluatedCallInfo; pub use crate::command_args::{ - CommandArgs, EvaluatedCommandArgs, EvaluatedWholeStreamCommandArgs, RawCommandArgs, - RunnableContext, RunnableContextWithoutInput, + CommandArgs, EvaluatedCommandArgs, EvaluatedCommandArgsWithoutInput, RunnableContext, }; pub use crate::config_holder::ConfigHolder; pub use crate::documentation::{generate_docs, get_brief_help, get_documentation, get_full_help}; diff --git a/crates/nu-engine/src/shell/mod.rs b/crates/nu-engine/src/shell/mod.rs index c97a9450d8..f4ca3c66e9 100644 --- a/crates/nu-engine/src/shell/mod.rs +++ b/crates/nu-engine/src/shell/mod.rs @@ -1,6 +1,6 @@ use nu_stream::{ActionStream, OutputStream}; -use crate::command_args::EvaluatedWholeStreamCommandArgs; +use crate::command_args::EvaluatedCommandArgs; use crate::maybe_text_codec::StringOrBinary; pub use crate::shell::shell_args::{CdArgs, CopyArgs, LsArgs, MkdirArgs, MvArgs, RemoveArgs}; use encoding_rs::Encoding; @@ -33,7 +33,7 @@ pub trait Shell: std::fmt::Debug { fn mv(&self, args: MvArgs, name: Tag, path: &str) -> Result; fn rm(&self, args: RemoveArgs, name: Tag, path: &str) -> Result; fn path(&self) -> String; - fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result; + fn pwd(&self, args: EvaluatedCommandArgs) -> Result; fn set_path(&mut self, path: String); fn open( &self, diff --git a/crates/nu-engine/src/shell/shell_manager.rs b/crates/nu-engine/src/shell/shell_manager.rs index f07fa7d685..13725a2693 100644 --- a/crates/nu-engine/src/shell/shell_manager.rs +++ b/crates/nu-engine/src/shell/shell_manager.rs @@ -1,5 +1,5 @@ use crate::shell::Shell; -use crate::{command_args::EvaluatedWholeStreamCommandArgs, FilesystemShell}; +use crate::{command_args::EvaluatedCommandArgs, FilesystemShell}; use crate::{filesystem::filesystem_shell::FilesystemShellMode, maybe_text_codec::StringOrBinary}; use nu_stream::{ActionStream, OutputStream}; @@ -19,6 +19,15 @@ pub struct ShellManager { } impl ShellManager { + pub fn basic() -> ShellManager { + ShellManager { + current_shell: Arc::new(AtomicUsize::new(0)), + shells: Arc::new(Mutex::new(vec![Box::new(FilesystemShell::basic( + FilesystemShellMode::Cli, + ))])), + } + } + pub fn enter_script_mode(&self) -> Result<(), std::io::Error> { //New fs_shell starting from current path let fs_shell = FilesystemShell::with_location(self.path(), FilesystemShellMode::Script)?; @@ -69,7 +78,7 @@ impl ShellManager { self.shells.lock()[self.current_shell()].path() } - pub fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { + pub fn pwd(&self, args: EvaluatedCommandArgs) -> Result { let env = self.shells.lock(); env[self.current_shell()].pwd(args) diff --git a/crates/nu-engine/src/shell/value_shell.rs b/crates/nu-engine/src/shell/value_shell.rs index 31b5fca473..1946ee1a6a 100644 --- a/crates/nu-engine/src/shell/value_shell.rs +++ b/crates/nu-engine/src/shell/value_shell.rs @@ -1,4 +1,4 @@ -use crate::command_args::EvaluatedWholeStreamCommandArgs; +use crate::command_args::EvaluatedCommandArgs; use crate::maybe_text_codec::StringOrBinary; use crate::shell::shell_args::{CdArgs, CopyArgs, LsArgs, MkdirArgs, MvArgs, RemoveArgs}; use crate::shell::Shell; @@ -217,7 +217,7 @@ impl Shell for ValueShell { self.path.clone() } - fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result { + fn pwd(&self, args: EvaluatedCommandArgs) -> Result { Ok(ActionStream::one( UntaggedValue::string(self.path()).into_value(&args.call_info.name_tag), )) diff --git a/crates/nu-engine/src/whole_stream_command.rs b/crates/nu-engine/src/whole_stream_command.rs index ba5c25db87..cc8e00b60d 100644 --- a/crates/nu-engine/src/whole_stream_command.rs +++ b/crates/nu-engine/src/whole_stream_command.rs @@ -237,7 +237,8 @@ impl Command { if args.call_info.switch_present("help") { let cl = self.0.clone(); Ok(ActionStream::one(Ok(ReturnSuccess::Value( - UntaggedValue::string(get_full_help(&*cl, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&*cl, &args.context.scope)) + .into_value(Tag::unknown()), )))) } else { self.0.run_with_actions(args) @@ -248,7 +249,8 @@ impl Command { if args.call_info.switch_present("help") { let cl = self.0.clone(); Ok(InputStream::one( - UntaggedValue::string(get_full_help(&*cl, &args.scope)).into_value(Tag::unknown()), + UntaggedValue::string(get_full_help(&*cl, &args.context.scope)) + .into_value(Tag::unknown()), )) } else { self.0.run(args)