diff --git a/crates/nu-command/src/commands/all.rs b/crates/nu-command/src/commands/all.rs index 9478a9d615..39a038400e 100644 --- a/crates/nu-command/src/commands/all.rs +++ b/crates/nu-command/src/commands/all.rs @@ -52,7 +52,7 @@ impl WholeStreamCommand for Command { } fn all(args: CommandArgs) -> Result { - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let tag = args.call_info.name_tag.clone(); let all_args = AllArgs { predicate: args.req(0)?, diff --git a/crates/nu-command/src/commands/any.rs b/crates/nu-command/src/commands/any.rs index 226170e2ef..f69fea8c1d 100644 --- a/crates/nu-command/src/commands/any.rs +++ b/crates/nu-command/src/commands/any.rs @@ -52,7 +52,7 @@ impl WholeStreamCommand for Command { } fn any(args: CommandArgs) -> Result { - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let tag = args.call_info.name_tag.clone(); let any_args = AnyArgs { predicate: args.req(0)?, diff --git a/crates/nu-command/src/commands/autoenv_trust.rs b/crates/nu-command/src/commands/autoenv_trust.rs index 8163ccbcb3..f4322ffd68 100644 --- a/crates/nu-command/src/commands/autoenv_trust.rs +++ b/crates/nu-command/src/commands/autoenv_trust.rs @@ -23,7 +23,7 @@ impl WholeStreamCommand for AutoenvTrust { fn run_with_actions(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let file_to_trust = match args.call_info.evaluate(&ctx)?.args.nth(0) { Some(Value { diff --git a/crates/nu-command/src/commands/autoenv_untrust.rs b/crates/nu-command/src/commands/autoenv_untrust.rs index 6cdf538394..8d47015211 100644 --- a/crates/nu-command/src/commands/autoenv_untrust.rs +++ b/crates/nu-command/src/commands/autoenv_untrust.rs @@ -27,7 +27,7 @@ impl WholeStreamCommand for AutoenvUnTrust { fn run_with_actions(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let file_to_untrust = match args.call_info.evaluate(&ctx)?.args.nth(0) { Some(Value { value: UntaggedValue::Primitive(Primitive::String(ref path)), diff --git a/crates/nu-command/src/commands/benchmark.rs b/crates/nu-command/src/commands/benchmark.rs index a090c1aaad..b74e57c038 100644 --- a/crates/nu-command/src/commands/benchmark.rs +++ b/crates/nu-command/src/commands/benchmark.rs @@ -71,7 +71,7 @@ impl WholeStreamCommand for Benchmark { fn benchmark(args: CommandArgs) -> Result { let tag = args.call_info.args.span; - let mut context = EvaluationContext::from_args(&args); + let mut context = args.context.clone(); let scope = args.scope().clone(); let cmd_args = BenchmarkArgs { diff --git a/crates/nu-command/src/commands/config/clear.rs b/crates/nu-command/src/commands/config/clear.rs index 90e033459f..0aa8593dfa 100644 --- a/crates/nu-command/src/commands/config/clear.rs +++ b/crates/nu-command/src/commands/config/clear.rs @@ -33,7 +33,7 @@ impl WholeStreamCommand for SubCommand { pub fn clear(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let result = if let Some(global_cfg) = &mut args.configs().lock().global_config { global_cfg.vars.clear(); diff --git a/crates/nu-command/src/commands/config/get.rs b/crates/nu-command/src/commands/config/get.rs index ca09607e4d..0bc52fe6d0 100644 --- a/crates/nu-command/src/commands/config/get.rs +++ b/crates/nu-command/src/commands/config/get.rs @@ -37,7 +37,7 @@ impl WholeStreamCommand for SubCommand { pub fn get(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let column_path = args.req(0)?; diff --git a/crates/nu-command/src/commands/config/remove.rs b/crates/nu-command/src/commands/config/remove.rs index a15a073fd3..44e4bf829a 100644 --- a/crates/nu-command/src/commands/config/remove.rs +++ b/crates/nu-command/src/commands/config/remove.rs @@ -38,7 +38,7 @@ impl WholeStreamCommand for SubCommand { pub fn remove(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let remove: Tagged = args.req(0)?; let key = remove.to_string(); diff --git a/crates/nu-command/src/commands/config/set.rs b/crates/nu-command/src/commands/config/set.rs index fea8ac3a37..cb4dd77c63 100644 --- a/crates/nu-command/src/commands/config/set.rs +++ b/crates/nu-command/src/commands/config/set.rs @@ -52,7 +52,7 @@ impl WholeStreamCommand for SubCommand { pub fn set(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let column_path = args.req(0)?; let mut value: Value = args.req(1)?; diff --git a/crates/nu-command/src/commands/config/set_into.rs b/crates/nu-command/src/commands/config/set_into.rs index fa9e95227b..68c645c52b 100644 --- a/crates/nu-command/src/commands/config/set_into.rs +++ b/crates/nu-command/src/commands/config/set_into.rs @@ -38,7 +38,7 @@ impl WholeStreamCommand for SubCommand { pub fn set_into(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let set_into: Tagged = args.req(0)?; diff --git a/crates/nu-command/src/commands/each/window.rs b/crates/nu-command/src/commands/each/window.rs index f8889acbe5..b25a867002 100644 --- a/crates/nu-command/src/commands/each/window.rs +++ b/crates/nu-command/src/commands/each/window.rs @@ -42,7 +42,7 @@ impl WholeStreamCommand for EachWindow { } fn run(&self, mut args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let external_redirection = args.call_info.args.external_redirection; let window_size: Tagged = args.req(0)?; diff --git a/crates/nu-command/src/commands/empty.rs b/crates/nu-command/src/commands/empty.rs index ecba53758c..5f7faae973 100644 --- a/crates/nu-command/src/commands/empty.rs +++ b/crates/nu-command/src/commands/empty.rs @@ -82,23 +82,21 @@ impl WholeStreamCommand for Command { fn is_empty(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let name_tag = Arc::new(args.call_info.name_tag.clone()); - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = args.context.clone(); let block: Option = args.get_flag("block")?; let columns: Vec = args.rest(0)?; let input = args.input; if input.is_empty() { - let stream = vec![UntaggedValue::Primitive(Primitive::Nothing).into_value(tag)].into_iter(); + let stream = + vec![UntaggedValue::Primitive(Primitive::Nothing).into_value(&tag)].into_iter(); return Ok(InputStream::from_stream(stream) .map(move |input| { - let tag = name_tag.clone(); - let context = context.clone(); let columns = vec![]; - match process_row(context, input, &block, columns, tag) { + match process_row(&context, input, &block, columns) { Ok(s) => s, Err(e) => ActionStream::one(Err(e)), } @@ -109,11 +107,9 @@ fn is_empty(args: CommandArgs) -> Result { Ok(input .map(move |input| { - let tag = name_tag.clone(); - let context = context.clone(); let columns = columns.clone(); - match process_row(context, input, &block, columns, tag) { + match process_row(&context, input, &block, columns) { Ok(s) => s, Err(e) => ActionStream::one(Err(e)), } @@ -123,13 +119,11 @@ fn is_empty(args: CommandArgs) -> Result { } fn process_row( - context: Arc, + context: &EvaluationContext, input: Value, default_block: &Option, column_paths: Vec, - tag: Arc, ) -> Result { - let _tag = &*tag; let mut out = Arc::new(None); let results = Arc::make_mut(&mut out); diff --git a/crates/nu-command/src/commands/for_in.rs b/crates/nu-command/src/commands/for_in.rs index 46a798ea79..b57b10788c 100644 --- a/crates/nu-command/src/commands/for_in.rs +++ b/crates/nu-command/src/commands/for_in.rs @@ -66,8 +66,8 @@ impl WholeStreamCommand for ForIn { } pub fn process_row( - captured_block: Arc>, - context: Arc, + captured_block: &CapturedBlock, + context: &EvaluationContext, input: Value, var_name: &str, external_redirection: ExternalRedirection, @@ -108,12 +108,12 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value { dict.into_value() } -fn for_in(raw_args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&raw_args)); - let external_redirection = raw_args.call_info.args.external_redirection; +fn for_in(args: CommandArgs) -> Result { + let context = args.context.clone(); + let external_redirection = args.call_info.args.external_redirection; // - let numbered: bool = raw_args.call_info.switch_present("numbered"); - let positional = raw_args + let numbered: bool = args.call_info.switch_present("numbered"); + let positional = args .call_info .args .positional @@ -126,17 +126,14 @@ fn for_in(raw_args: CommandArgs) -> Result { FromValue::from_value(&evaluate_baseline_expr(&positional[3], &context)?)?; let input = crate::commands::echo::expand_value_to_stream(rhs); - let block = Arc::new(Box::new(block)); if numbered { Ok(input .enumerate() .map(move |input| { - let block = block.clone(); - let context = context.clone(); let row = make_indexed_item(input.0, input.1); - match process_row(block, context, row, &var_name, external_redirection) { + match process_row(&block, &context, row, &var_name, external_redirection) { Ok(s) => s, Err(e) => OutputStream::one(Value::error(e)), } @@ -147,9 +144,8 @@ fn for_in(raw_args: CommandArgs) -> Result { Ok(input .map(move |input| { let block = block.clone(); - let context = context.clone(); - match process_row(block, context, input, &var_name, external_redirection) { + match process_row(&block, &context, input, &var_name, external_redirection) { Ok(s) => s, Err(e) => OutputStream::one(Value::error(e)), } diff --git a/crates/nu-command/src/commands/format/command.rs b/crates/nu-command/src/commands/format/command.rs index d10c20e88b..cf4cbf3a6e 100644 --- a/crates/nu-command/src/commands/format/command.rs +++ b/crates/nu-command/src/commands/format/command.rs @@ -39,7 +39,7 @@ impl WholeStreamCommand for Format { } fn format_command(args: CommandArgs) -> Result { - let ctx = Arc::new(EvaluationContext::from_args(&args)); + let ctx = Arc::new(args.context.clone()); let pattern: Tagged = args.req(0)?; let format_pattern = format(&pattern); diff --git a/crates/nu-command/src/commands/group_by.rs b/crates/nu-command/src/commands/group_by.rs index 746aaece16..7829fe2eaa 100644 --- a/crates/nu-command/src/commands/group_by.rs +++ b/crates/nu-command/src/commands/group_by.rs @@ -125,7 +125,7 @@ enum Grouper { pub fn group_by(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let grouper = args.opt(0)?; let values: Vec = args.input.collect(); diff --git a/crates/nu-command/src/commands/history.rs b/crates/nu-command/src/commands/history.rs index 74c30f4dd1..eb51153446 100644 --- a/crates/nu-command/src/commands/history.rs +++ b/crates/nu-command/src/commands/history.rs @@ -27,7 +27,7 @@ impl WholeStreamCommand for History { fn history(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let clear = args.has_flag("clear"); diff --git a/crates/nu-command/src/commands/insert.rs b/crates/nu-command/src/commands/insert.rs index 39c7ea1bdc..8d3e205ce7 100644 --- a/crates/nu-command/src/commands/insert.rs +++ b/crates/nu-command/src/commands/insert.rs @@ -153,7 +153,7 @@ fn process_row( } fn insert(args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let column: ColumnPath = args.req(0)?; let value: Value = args.req(1)?; let input = args.input; diff --git a/crates/nu-command/src/commands/keep/until.rs b/crates/nu-command/src/commands/keep/until.rs index c0e789853e..8b0741325f 100644 --- a/crates/nu-command/src/commands/keep/until.rs +++ b/crates/nu-command/src/commands/keep/until.rs @@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand { } fn run(&self, args: CommandArgs) -> Result { - let ctx = Arc::new(EvaluationContext::from_args(&args)); + let ctx = Arc::new(args.context.clone()); let tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/keep/while_.rs b/crates/nu-command/src/commands/keep/while_.rs index ecd703b5cb..d26fcdcb35 100644 --- a/crates/nu-command/src/commands/keep/while_.rs +++ b/crates/nu-command/src/commands/keep/while_.rs @@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand { } fn run(&self, args: CommandArgs) -> Result { - let ctx = Arc::new(EvaluationContext::from_args(&args)); + let ctx = Arc::new(args.context.clone()); let tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/let_.rs b/crates/nu-command/src/commands/let_.rs index 8b90baa13a..77fbfd9c82 100644 --- a/crates/nu-command/src/commands/let_.rs +++ b/crates/nu-command/src/commands/let_.rs @@ -55,7 +55,7 @@ impl WholeStreamCommand for Let { } pub fn letcmd(args: CommandArgs) -> Result { - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let positional = args .call_info .args diff --git a/crates/nu-command/src/commands/let_env.rs b/crates/nu-command/src/commands/let_env.rs index 9da1988c17..e638a0d707 100644 --- a/crates/nu-command/src/commands/let_env.rs +++ b/crates/nu-command/src/commands/let_env.rs @@ -49,7 +49,7 @@ impl WholeStreamCommand for LetEnv { pub fn set_env(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let name: Tagged = args.req(0)?; let rhs: CapturedBlock = args.req(2)?; diff --git a/crates/nu-command/src/commands/load_env.rs b/crates/nu-command/src/commands/load_env.rs index fa5eaade5a..c1eee26e46 100644 --- a/crates/nu-command/src/commands/load_env.rs +++ b/crates/nu-command/src/commands/load_env.rs @@ -82,7 +82,7 @@ fn load_env_from_table( } pub fn load_env(args: CommandArgs) -> Result { - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; if let Some(values) = args.opt::>(0)? { load_env_from_table(values, &ctx)?; diff --git a/crates/nu-command/src/commands/merge.rs b/crates/nu-command/src/commands/merge.rs index 42633ef716..710a19c371 100644 --- a/crates/nu-command/src/commands/merge.rs +++ b/crates/nu-command/src/commands/merge.rs @@ -42,7 +42,7 @@ impl WholeStreamCommand for Merge { } fn merge(args: CommandArgs) -> Result { - let context = EvaluationContext::from_args(&args); + let context = &args.context; let name_tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/reduce.rs b/crates/nu-command/src/commands/reduce.rs index a2fe3253c1..5eee3d7416 100644 --- a/crates/nu-command/src/commands/reduce.rs +++ b/crates/nu-command/src/commands/reduce.rs @@ -108,7 +108,7 @@ fn process_row( fn reduce(args: CommandArgs) -> Result { let span = args.call_info.name_tag.span; - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let reduce_args = ReduceArgs { block: args.req(0)?, fold: args.get_flag("fold")?, diff --git a/crates/nu-command/src/commands/skip/until.rs b/crates/nu-command/src/commands/skip/until.rs index b50e776e1a..51b5d3ab63 100644 --- a/crates/nu-command/src/commands/skip/until.rs +++ b/crates/nu-command/src/commands/skip/until.rs @@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let ctx = Arc::new(EvaluationContext::from_args(&args)); + let ctx = Arc::new(args.context.clone()); let tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/skip/while_.rs b/crates/nu-command/src/commands/skip/while_.rs index ff6248b6d9..77519bfd55 100644 --- a/crates/nu-command/src/commands/skip/while_.rs +++ b/crates/nu-command/src/commands/skip/while_.rs @@ -30,7 +30,7 @@ impl WholeStreamCommand for SubCommand { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let ctx = Arc::new(EvaluationContext::from_args(&args)); + let ctx = Arc::new(args.context.clone()); let tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/source.rs b/crates/nu-command/src/commands/source.rs index 98d5baf02d..ca2e67f6fc 100644 --- a/crates/nu-command/src/commands/source.rs +++ b/crates/nu-command/src/commands/source.rs @@ -40,7 +40,7 @@ impl WholeStreamCommand for Source { } pub fn source(args: CommandArgs) -> Result { - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let filename: Tagged = args.req(0)?; // Note: this is a special case for setting the context from a command diff --git a/crates/nu-command/src/commands/update.rs b/crates/nu-command/src/commands/update.rs index ef20ec19d6..abdfc32873 100644 --- a/crates/nu-command/src/commands/update.rs +++ b/crates/nu-command/src/commands/update.rs @@ -174,7 +174,7 @@ fn process_row( fn update(args: CommandArgs) -> Result { let name_tag = Arc::new(args.call_info.name_tag.clone()); - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let field: ColumnPath = args.req(0)?; let replacement: Value = args.req(1)?; diff --git a/crates/nu-command/src/commands/where_.rs b/crates/nu-command/src/commands/where_.rs index d855a5bca7..2ad0c42509 100644 --- a/crates/nu-command/src/commands/where_.rs +++ b/crates/nu-command/src/commands/where_.rs @@ -57,7 +57,7 @@ impl WholeStreamCommand for Command { } } fn where_command(args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&args)); + let context = Arc::new(args.context.clone()); let tag = args.call_info.name_tag.clone(); let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/with_env.rs b/crates/nu-command/src/commands/with_env.rs index acafc3d247..d41ee18827 100644 --- a/crates/nu-command/src/commands/with_env.rs +++ b/crates/nu-command/src/commands/with_env.rs @@ -69,7 +69,7 @@ impl WholeStreamCommand for WithEnv { fn with_env(args: CommandArgs) -> Result { let external_redirection = args.call_info.args.external_redirection; - let context = EvaluationContext::from_args(&args); + let context = &args.context; let variable: Value = args.req(0)?; let block: CapturedBlock = args.req(1)?; diff --git a/crates/nu-engine/src/evaluation_context.rs b/crates/nu-engine/src/evaluation_context.rs index 672e81f452..da32cda2b9 100644 --- a/crates/nu-engine/src/evaluation_context.rs +++ b/crates/nu-engine/src/evaluation_context.rs @@ -67,10 +67,6 @@ impl EvaluationContext { } } - pub fn from_args(args: &CommandArgs) -> EvaluationContext { - args.context.clone() - } - pub fn error(&self, error: ShellError) { self.with_errors(|errors| errors.push(error)) } diff --git a/crates/nu-engine/src/whole_stream_command.rs b/crates/nu-engine/src/whole_stream_command.rs index cc8e00b60d..8eb55694d2 100644 --- a/crates/nu-engine/src/whole_stream_command.rs +++ b/crates/nu-engine/src/whole_stream_command.rs @@ -1,7 +1,6 @@ use crate::command_args::CommandArgs; use crate::documentation::get_full_help; use crate::evaluate::block::run_block; -use crate::evaluation_context::EvaluationContext; use crate::example::Example; use nu_errors::ShellError; use nu_parser::ParserScope; @@ -32,7 +31,7 @@ pub trait WholeStreamCommand: Send + Sync { } fn run(&self, args: CommandArgs) -> Result { - let context = EvaluationContext::from_args(&args); + let context = args.context.clone(); let stream = self.run_with_actions(args)?; Ok(Box::new(crate::evaluate::internal::InternalIterator { @@ -81,7 +80,7 @@ impl WholeStreamCommand for Arc { let external_redirection = args.call_info.args.external_redirection; - let ctx = EvaluationContext::from_args(&args); + let ctx = &args.context; let evaluated = call_info.evaluate(&ctx)?; let input = args.input;