diff --git a/crates/nu-ansi-term/src/style.rs b/crates/nu-ansi-term/src/style.rs index 5348f0ae8a..ec72dbdb31 100644 --- a/crates/nu-ansi-term/src/style.rs +++ b/crates/nu-ansi-term/src/style.rs @@ -603,7 +603,7 @@ mod serde_json_tests { Color::Fixed(255), ]; - for color in colors.into_iter() { + for color in colors.iter() { let serialized = serde_json::to_string(&color).unwrap(); let deserialized: Color = serde_json::from_str(&serialized).unwrap(); diff --git a/crates/nu-command/src/commands.rs b/crates/nu-command/src/commands.rs index 183811762c..9309df3b70 100644 --- a/crates/nu-command/src/commands.rs +++ b/crates/nu-command/src/commands.rs @@ -1,6 +1,3 @@ -#[macro_use] -pub(crate) mod macros; - mod from_delimited_data; mod to_delimited_data; diff --git a/crates/nu-command/src/commands/all.rs b/crates/nu-command/src/commands/all.rs index 6320f68701..9478a9d615 100644 --- a/crates/nu-command/src/commands/all.rs +++ b/crates/nu-command/src/commands/all.rs @@ -54,7 +54,6 @@ impl WholeStreamCommand for Command { fn all(args: CommandArgs) -> Result { let ctx = EvaluationContext::from_args(&args); let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let all_args = AllArgs { predicate: args.req(0)?, }; @@ -83,7 +82,7 @@ fn all(args: CommandArgs) -> Result { } }; - let scope = args.scope(); + let scope = args.scope().clone(); let init = Ok(InputStream::one( UntaggedValue::boolean(true).into_value(&tag), diff --git a/crates/nu-command/src/commands/ansi/command.rs b/crates/nu-command/src/commands/ansi/command.rs index e37fbaa436..a5255e593c 100644 --- a/crates/nu-command/src/commands/ansi/command.rs +++ b/crates/nu-command/src/commands/ansi/command.rs @@ -113,8 +113,6 @@ Format: # } fn run(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let code: Option> = args.opt(0)?; let escape: Option> = args.get_flag("escape")?; let osc: Option> = args.get_flag("osc")?; @@ -170,7 +168,7 @@ Format: # Err(ShellError::labeled_error( "Expected ansi code", "expect ansi code", - args.call_info.name_tag.clone(), + &args.call_info.name_tag, )) } } diff --git a/crates/nu-command/src/commands/ansi/gradient.rs b/crates/nu-command/src/commands/ansi/gradient.rs index 0d71d636f4..935d767ed9 100644 --- a/crates/nu-command/src/commands/ansi/gradient.rs +++ b/crates/nu-command/src/commands/ansi/gradient.rs @@ -84,7 +84,6 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let fgstart: Option = args.get_flag("fgstart")?; let fgend: Option = args.get_flag("fgend")?; let bgstart: Option = args.get_flag("bgstart")?; diff --git a/crates/nu-command/src/commands/ansi/strip.rs b/crates/nu-command/src/commands/ansi/strip.rs index ede70a2a72..5dab2d9c70 100644 --- a/crates/nu-command/src/commands/ansi/strip.rs +++ b/crates/nu-command/src/commands/ansi/strip.rs @@ -38,8 +38,6 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let column_paths: Vec<_> = args.rest(0)?; let result: Vec = args diff --git a/crates/nu-command/src/commands/any.rs b/crates/nu-command/src/commands/any.rs index 0e435cf2c2..226170e2ef 100644 --- a/crates/nu-command/src/commands/any.rs +++ b/crates/nu-command/src/commands/any.rs @@ -54,7 +54,6 @@ impl WholeStreamCommand for Command { fn any(args: CommandArgs) -> Result { let ctx = EvaluationContext::from_args(&args); let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let any_args = AnyArgs { predicate: args.req(0)?, }; @@ -83,7 +82,7 @@ fn any(args: CommandArgs) -> Result { } }; - let scope = args.scope(); + let scope = args.scope().clone(); let init = Ok(InputStream::one( UntaggedValue::boolean(false).into_value(&tag), diff --git a/crates/nu-command/src/commands/append.rs b/crates/nu-command/src/commands/append.rs index 618600c9fc..d2700eb250 100644 --- a/crates/nu-command/src/commands/append.rs +++ b/crates/nu-command/src/commands/append.rs @@ -22,8 +22,7 @@ impl WholeStreamCommand for Command { "Append a row to the table." } - fn run(&self, args: CommandArgs) -> Result { - let mut args = args.evaluate_once()?; + fn run(&self, mut args: CommandArgs) -> Result { let mut value: Value = args.req(0)?; let mut prepend = vec![]; diff --git a/crates/nu-command/src/commands/benchmark.rs b/crates/nu-command/src/commands/benchmark.rs index 94005cc275..a090c1aaad 100644 --- a/crates/nu-command/src/commands/benchmark.rs +++ b/crates/nu-command/src/commands/benchmark.rs @@ -74,7 +74,6 @@ fn benchmark(args: CommandArgs) -> Result { let mut context = EvaluationContext::from_args(&args); let scope = args.scope().clone(); - let args = args.evaluate_once()?; let cmd_args = BenchmarkArgs { block: args.req(0)?, passthrough: args.get_flag("passthrough")?, diff --git a/crates/nu-command/src/commands/build_string.rs b/crates/nu-command/src/commands/build_string.rs index 113a15dab9..bca2617ecf 100644 --- a/crates/nu-command/src/commands/build_string.rs +++ b/crates/nu-command/src/commands/build_string.rs @@ -23,7 +23,6 @@ impl WholeStreamCommand for BuildString { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let mut output_string = String::new(); diff --git a/crates/nu-command/src/commands/cal.rs b/crates/nu-command/src/commands/cal.rs index c8442c4fe2..04a6d26e00 100644 --- a/crates/nu-command/src/commands/cal.rs +++ b/crates/nu-command/src/commands/cal.rs @@ -1,9 +1,10 @@ use crate::prelude::*; use chrono::{Datelike, Local, NaiveDate}; use indexmap::IndexMap; -use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand}; +use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value}; +use nu_source::Tagged; pub struct Cal; @@ -66,7 +67,6 @@ impl WholeStreamCommand for Cal { } pub fn cal(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let mut calendar_vec_deque = VecDeque::new(); let tag = args.call_info.name_tag.clone(); @@ -75,15 +75,12 @@ pub fn cal(args: CommandArgs) -> Result { let mut selected_year: i32 = current_year; let mut current_day_option: Option = Some(current_day); - let month_range = if let Some(full_year_value) = args.call_info.args.get("full-year") { - if let Ok(year_u64) = full_year_value.as_u64() { - selected_year = year_u64 as i32; + let full_year_value: Option = args.get_flag("full-year")?; + let month_range = if let Some(full_year_value) = full_year_value { + selected_year = full_year_value as i32; - if selected_year != current_year { - current_day_option = None - } - } else { - return Err(get_invalid_year_shell_error(&full_year_value.tag())); + if selected_year != current_year { + current_day_option = None } (1, 12) @@ -165,7 +162,7 @@ fn get_current_date() -> (i32, u32, u32) { } fn add_months_of_year_to_table( - args: &EvaluatedCommandArgs, + args: &CommandArgs, mut calendar_vec_deque: &mut VecDeque, tag: &Tag, selected_year: i32, @@ -198,7 +195,7 @@ fn add_months_of_year_to_table( } fn add_month_to_table( - args: &EvaluatedCommandArgs, + args: &CommandArgs, calendar_vec_deque: &mut VecDeque, tag: &Tag, selected_year: i32, @@ -207,9 +204,11 @@ fn add_month_to_table( ) -> Result<(), ShellError> { let month_helper_result = MonthHelper::new(selected_year, current_month); + let full_year_value: Option> = args.get_flag("full-year")?; + let month_helper = match month_helper_result { Ok(month_helper) => month_helper, - Err(()) => match args.call_info.args.get("full-year") { + Err(()) => match full_year_value { Some(full_year_value) => { return Err(get_invalid_year_shell_error(&full_year_value.tag())) } @@ -235,17 +234,15 @@ fn add_month_to_table( let mut week_start_day = days_of_the_week[0].to_string(); - if let Some(week_start_value) = args.call_info.args.get("week-start") { - if let Ok(day) = week_start_value.as_string() { - if days_of_the_week.contains(&day.as_str()) { - week_start_day = day; - } else { - return Err(ShellError::labeled_error( - "The specified week start day is invalid", - "invalid week start day", - week_start_value.tag(), - )); - } + if let Some(day) = args.get_flag::>("week-start")? { + if days_of_the_week.contains(&day.item.as_str()) { + week_start_day = day.item; + } else { + return Err(ShellError::labeled_error( + "The specified week start day is invalid", + "invalid week start day", + day.tag(), + )); } } diff --git a/crates/nu-command/src/commands/cd.rs b/crates/nu-command/src/commands/cd.rs index d25dafca53..f6c29130ea 100644 --- a/crates/nu-command/src/commands/cd.rs +++ b/crates/nu-command/src/commands/cd.rs @@ -27,7 +27,6 @@ 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(); - let args = args.evaluate_once()?; let args = CdArgs { path: args.opt(0)? }; shell_manager.cd(args, name) diff --git a/crates/nu-command/src/commands/char_.rs b/crates/nu-command/src/commands/char_.rs index e51f72345e..f59cde5f06 100644 --- a/crates/nu-command/src/commands/char_.rs +++ b/crates/nu-command/src/commands/char_.rs @@ -168,7 +168,6 @@ impl WholeStreamCommand for Char { fn run(&self, args: CommandArgs) -> Result { let args_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let args = CharArgs { name: args.opt(0)?, rest: args.rest(1)?, diff --git a/crates/nu-command/src/commands/compact.rs b/crates/nu-command/src/commands/compact.rs index 0b17683a06..d6774e0300 100644 --- a/crates/nu-command/src/commands/compact.rs +++ b/crates/nu-command/src/commands/compact.rs @@ -38,11 +38,12 @@ impl WholeStreamCommand for Compact { } pub fn compact(args: CommandArgs) -> Result { - let (args, input) = args.extract(|params| { - Ok(CompactArgs { - columns: params.rest(0)?, - }) - })?; + let (args, input) = ( + CompactArgs { + columns: args.rest(0)?, + }, + args.input, + ); Ok(input .filter(move |item| { diff --git a/crates/nu-command/src/commands/config/get.rs b/crates/nu-command/src/commands/config/get.rs index 367bcff0a8..ca09607e4d 100644 --- a/crates/nu-command/src/commands/config/get.rs +++ b/crates/nu-command/src/commands/config/get.rs @@ -38,7 +38,6 @@ 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 args = args.evaluate_once()?; 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 9c3823aac2..a15a073fd3 100644 --- a/crates/nu-command/src/commands/config/remove.rs +++ b/crates/nu-command/src/commands/config/remove.rs @@ -39,7 +39,6 @@ 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 args = args.evaluate_once()?; 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 289f17d87a..fea8ac3a37 100644 --- a/crates/nu-command/src/commands/config/set.rs +++ b/crates/nu-command/src/commands/config/set.rs @@ -53,7 +53,6 @@ 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 args = args.evaluate_once()?; 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 a5b765da69..fa9e95227b 100644 --- a/crates/nu-command/src/commands/config/set_into.rs +++ b/crates/nu-command/src/commands/config/set_into.rs @@ -39,7 +39,6 @@ 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 args = args.evaluate_once()?; let set_into: Tagged = args.req(0)?; diff --git a/crates/nu-command/src/commands/cp.rs b/crates/nu-command/src/commands/cp.rs index ba7f4e090f..6794424e2a 100644 --- a/crates/nu-command/src/commands/cp.rs +++ b/crates/nu-command/src/commands/cp.rs @@ -28,7 +28,6 @@ impl WholeStreamCommand for Cpy { fn run_with_actions(&self, args: CommandArgs) -> Result { let shell_manager = args.shell_manager(); let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let args = CopyArgs { src: args.req(0)?, diff --git a/crates/nu-command/src/commands/dataframe/aggregate.rs b/crates/nu-command/src/commands/dataframe/aggregate.rs index 83346fc54a..1a0f3a3118 100644 --- a/crates/nu-command/src/commands/dataframe/aggregate.rs +++ b/crates/nu-command/src/commands/dataframe/aggregate.rs @@ -121,9 +121,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let quantile: Option> = args.get_flag("quantile")?; let operation: Tagged = args.req(0)?; @@ -139,11 +138,9 @@ fn command(args: CommandArgs) -> Result { None => (None, Span::unknown()), }; - let value = args.input.next().ok_or(ShellError::labeled_error( - "Empty stream", - "No value found in the stream", - &tag, - ))?; + let value = args.input.next().ok_or_else(|| { + ShellError::labeled_error("Empty stream", "No value found in the stream", &tag) + })?; let res = match value.value { UntaggedValue::DataFrame(PolarsData::GroupBy(nu_groupby)) => { diff --git a/crates/nu-command/src/commands/dataframe/column.rs b/crates/nu-command/src/commands/dataframe/column.rs index b82acd2a6b..a178913253 100644 --- a/crates/nu-command/src/commands/dataframe/column.rs +++ b/crates/nu-command/src/commands/dataframe/column.rs @@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let column: Tagged = args.req(0)?; let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; diff --git a/crates/nu-command/src/commands/dataframe/drop.rs b/crates/nu-command/src/commands/dataframe/drop.rs index 4407460102..33557ef7c0 100644 --- a/crates/nu-command/src/commands/dataframe/drop.rs +++ b/crates/nu-command/src/commands/dataframe/drop.rs @@ -37,16 +37,15 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let columns: Vec = args.req(0)?; let (col_string, col_span) = convert_columns(&columns, &tag)?; let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; - let new_df = match col_string.iter().next() { + let new_df = match col_string.get(0) { Some(col) => df .as_ref() .drop(col) diff --git a/crates/nu-command/src/commands/dataframe/drop_duplicates.rs b/crates/nu-command/src/commands/dataframe/drop_duplicates.rs index 372d9b5c0e..635afda920 100644 --- a/crates/nu-command/src/commands/dataframe/drop_duplicates.rs +++ b/crates/nu-command/src/commands/dataframe/drop_duplicates.rs @@ -39,9 +39,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; // Extracting the selection columns of the columns to perform the aggregation let columns: Option> = args.opt(0)?; diff --git a/crates/nu-command/src/commands/dataframe/drop_nulls.rs b/crates/nu-command/src/commands/dataframe/drop_nulls.rs index a32f847195..24df7b2b24 100644 --- a/crates/nu-command/src/commands/dataframe/drop_nulls.rs +++ b/crates/nu-command/src/commands/dataframe/drop_nulls.rs @@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; // Extracting the selection columns of the columns to perform the aggregation let columns: Option> = args.opt(0)?; diff --git a/crates/nu-command/src/commands/dataframe/dtypes.rs b/crates/nu-command/src/commands/dataframe/dtypes.rs index be1f91307b..2080ed0859 100644 --- a/crates/nu-command/src/commands/dataframe/dtypes.rs +++ b/crates/nu-command/src/commands/dataframe/dtypes.rs @@ -31,9 +31,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; let col_names = df diff --git a/crates/nu-command/src/commands/dataframe/dummies.rs b/crates/nu-command/src/commands/dataframe/dummies.rs index be3c7b2929..ed5d492397 100644 --- a/crates/nu-command/src/commands/dataframe/dummies.rs +++ b/crates/nu-command/src/commands/dataframe/dummies.rs @@ -33,9 +33,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; let res = df.as_ref().to_dummies().map_err(|e| { diff --git a/crates/nu-command/src/commands/dataframe/get.rs b/crates/nu-command/src/commands/dataframe/get.rs index 25711fb739..695740bdf5 100644 --- a/crates/nu-command/src/commands/dataframe/get.rs +++ b/crates/nu-command/src/commands/dataframe/get.rs @@ -36,9 +36,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let columns: Vec = args.req(0)?; let (col_string, col_span) = convert_columns(&columns, &tag)?; diff --git a/crates/nu-command/src/commands/dataframe/groupby.rs b/crates/nu-command/src/commands/dataframe/groupby.rs index 80c2072059..8af40e3922 100644 --- a/crates/nu-command/src/commands/dataframe/groupby.rs +++ b/crates/nu-command/src/commands/dataframe/groupby.rs @@ -40,9 +40,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; // Extracting the names of the columns to perform the groupby let by_columns: Vec = args.req(0)?; diff --git a/crates/nu-command/src/commands/dataframe/head.rs b/crates/nu-command/src/commands/dataframe/head.rs index 49ecfdd7bb..e9e4317ea6 100644 --- a/crates/nu-command/src/commands/dataframe/head.rs +++ b/crates/nu-command/src/commands/dataframe/head.rs @@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let rows = match rows { diff --git a/crates/nu-command/src/commands/dataframe/join.rs b/crates/nu-command/src/commands/dataframe/join.rs index 9b89025d62..f7206cd361 100644 --- a/crates/nu-command/src/commands/dataframe/join.rs +++ b/crates/nu-command/src/commands/dataframe/join.rs @@ -65,9 +65,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let r_df: Value = args.req(0)?; let l_col: Vec = args.req(1)?; diff --git a/crates/nu-command/src/commands/dataframe/list.rs b/crates/nu-command/src/commands/dataframe/list.rs index 65965853c8..f059f349ad 100644 --- a/crates/nu-command/src/commands/dataframe/list.rs +++ b/crates/nu-command/src/commands/dataframe/list.rs @@ -19,8 +19,6 @@ impl WholeStreamCommand for DataFrame { } fn run(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let values = args .context .scope diff --git a/crates/nu-command/src/commands/dataframe/load.rs b/crates/nu-command/src/commands/dataframe/load.rs index eef2eb4330..19316ecf52 100644 --- a/crates/nu-command/src/commands/dataframe/load.rs +++ b/crates/nu-command/src/commands/dataframe/load.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use crate::{commands::dataframe::utils::parse_polars_error, prelude::*}; -use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand}; +use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::{ dataframe::NuDataFrame, Primitive, Signature, SyntaxShape, UntaggedValue, Value, @@ -75,7 +75,6 @@ impl WholeStreamCommand for DataFrame { fn command(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let file: Tagged = args.req(0)?; let df = match file.item().extension() { @@ -108,7 +107,7 @@ fn command(args: CommandArgs) -> Result { }; let df_tag = Tag { - anchor: Some(AnchorLocation::File(file_name.to_string())), + anchor: Some(AnchorLocation::File(file_name)), span: tag.span, }; @@ -117,7 +116,7 @@ fn command(args: CommandArgs) -> Result { ))) } -fn from_parquet(args: EvaluatedCommandArgs) -> Result { +fn from_parquet(args: CommandArgs) -> Result { let file: Tagged = args.req(0)?; let r = File::open(&file.item) @@ -130,7 +129,7 @@ fn from_parquet(args: EvaluatedCommandArgs) -> Result(&e, &file.tag.span, None)) } -fn from_json(args: EvaluatedCommandArgs) -> Result { +fn from_json(args: CommandArgs) -> Result { let file: Tagged = args.req(0)?; let r = File::open(&file.item) @@ -143,7 +142,7 @@ fn from_json(args: EvaluatedCommandArgs) -> Result(&e, &file.tag.span, None)) } -fn from_csv(args: EvaluatedCommandArgs) -> Result { +fn from_csv(args: CommandArgs) -> Result { let file: Tagged = args.req(0)?; let delimiter: Option> = args.get_flag("delimiter")?; let no_header: bool = args.has_flag("no_header"); @@ -164,7 +163,7 @@ fn from_csv(args: EvaluatedCommandArgs) -> Result d as u8, None => unreachable!(), }; diff --git a/crates/nu-command/src/commands/dataframe/melt.rs b/crates/nu-command/src/commands/dataframe/melt.rs index 283a084350..7156b2ff06 100644 --- a/crates/nu-command/src/commands/dataframe/melt.rs +++ b/crates/nu-command/src/commands/dataframe/melt.rs @@ -39,9 +39,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let id_col: Vec = args.req(0)?; let val_col: Vec = args.req(1)?; @@ -67,7 +66,7 @@ fn check_column_datatypes>( cols: &[T], col_span: &Span, ) -> Result<(), ShellError> { - if cols.len() == 0 { + if cols.is_empty() { return Err(ShellError::labeled_error( "Merge error", "empty column list", diff --git a/crates/nu-command/src/commands/dataframe/pivot.rs b/crates/nu-command/src/commands/dataframe/pivot.rs index 84ae324cf9..94e247c108 100644 --- a/crates/nu-command/src/commands/dataframe/pivot.rs +++ b/crates/nu-command/src/commands/dataframe/pivot.rs @@ -78,9 +78,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; // Extracting the pivot col from arguments let pivot_col: Tagged = args.req(0)?; diff --git a/crates/nu-command/src/commands/dataframe/sample.rs b/crates/nu-command/src/commands/dataframe/sample.rs index 83918f6dec..11c42810ed 100644 --- a/crates/nu-command/src/commands/dataframe/sample.rs +++ b/crates/nu-command/src/commands/dataframe/sample.rs @@ -53,9 +53,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let rows: Option> = args.get_flag("n_rows")?; let fraction: Option> = args.get_flag("fraction")?; diff --git a/crates/nu-command/src/commands/dataframe/select.rs b/crates/nu-command/src/commands/dataframe/select.rs index e719fcfcc7..48b0086326 100644 --- a/crates/nu-command/src/commands/dataframe/select.rs +++ b/crates/nu-command/src/commands/dataframe/select.rs @@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let columns: Vec = args.req(0)?; diff --git a/crates/nu-command/src/commands/dataframe/show.rs b/crates/nu-command/src/commands/dataframe/show.rs index 38bf00d7ee..95ffcf2dcd 100644 --- a/crates/nu-command/src/commands/dataframe/show.rs +++ b/crates/nu-command/src/commands/dataframe/show.rs @@ -47,9 +47,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let rows: Option> = args.get_flag("n_rows")?; let tail: bool = args.has_flag("tail"); diff --git a/crates/nu-command/src/commands/dataframe/slice.rs b/crates/nu-command/src/commands/dataframe/slice.rs index 84cb016bed..3dc7f69de7 100644 --- a/crates/nu-command/src/commands/dataframe/slice.rs +++ b/crates/nu-command/src/commands/dataframe/slice.rs @@ -34,9 +34,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let offset: Tagged = args.req(0)?; let size: Tagged = args.req(1)?; diff --git a/crates/nu-command/src/commands/dataframe/sort.rs b/crates/nu-command/src/commands/dataframe/sort.rs index fadf1e1f78..36f4dcaa5f 100644 --- a/crates/nu-command/src/commands/dataframe/sort.rs +++ b/crates/nu-command/src/commands/dataframe/sort.rs @@ -38,9 +38,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let columns: Vec = args.req(0)?; let reverse = args.has_flag("reverse"); diff --git a/crates/nu-command/src/commands/dataframe/tail.rs b/crates/nu-command/src/commands/dataframe/tail.rs index 9d6b7acdcb..010613e15b 100644 --- a/crates/nu-command/src/commands/dataframe/tail.rs +++ b/crates/nu-command/src/commands/dataframe/tail.rs @@ -36,9 +36,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let rows = match rows { diff --git a/crates/nu-command/src/commands/dataframe/to_csv.rs b/crates/nu-command/src/commands/dataframe/to_csv.rs index a34d8f0934..c554ebdf63 100644 --- a/crates/nu-command/src/commands/dataframe/to_csv.rs +++ b/crates/nu-command/src/commands/dataframe/to_csv.rs @@ -57,9 +57,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let file_name: Tagged = args.req(0)?; let delimiter: Option> = args.get_flag("delimiter")?; let no_header: bool = args.has_flag("no_header"); @@ -92,7 +91,7 @@ fn command(args: CommandArgs) -> Result { &d.tag, )); } else { - let delimiter = match d.item.chars().nth(0) { + let delimiter = match d.item.chars().next() { Some(d) => d as u8, None => unreachable!(), }; diff --git a/crates/nu-command/src/commands/dataframe/to_df.rs b/crates/nu-command/src/commands/dataframe/to_df.rs index 57b75d8914..26ad3ee948 100644 --- a/crates/nu-command/src/commands/dataframe/to_df.rs +++ b/crates/nu-command/src/commands/dataframe/to_df.rs @@ -20,7 +20,6 @@ impl WholeStreamCommand for DataFrame { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let df = NuDataFrame::try_from_iter(args.input, &tag)?; diff --git a/crates/nu-command/src/commands/dataframe/to_parquet.rs b/crates/nu-command/src/commands/dataframe/to_parquet.rs index 0f827c0199..f5ed1ab6a4 100644 --- a/crates/nu-command/src/commands/dataframe/to_parquet.rs +++ b/crates/nu-command/src/commands/dataframe/to_parquet.rs @@ -44,9 +44,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let file_name: Tagged = args.req(0)?; let mut df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; diff --git a/crates/nu-command/src/commands/dataframe/to_series.rs b/crates/nu-command/src/commands/dataframe/to_series.rs index 3143139154..627a874746 100644 --- a/crates/nu-command/src/commands/dataframe/to_series.rs +++ b/crates/nu-command/src/commands/dataframe/to_series.rs @@ -25,7 +25,6 @@ impl WholeStreamCommand for DataFrame { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let name: Option> = args.opt(0)?; let name = name.map(|v| v.item); diff --git a/crates/nu-command/src/commands/dataframe/utils.rs b/crates/nu-command/src/commands/dataframe/utils.rs index 33ef3e2e65..2a17146eb2 100644 --- a/crates/nu-command/src/commands/dataframe/utils.rs +++ b/crates/nu-command/src/commands/dataframe/utils.rs @@ -5,13 +5,12 @@ use polars::prelude::PolarsError; // Converts a Vec to a Vec with a Span marking the whole // location of the columns for error referencing -pub(crate) fn convert_columns<'columns>( - columns: &'columns [Value], +pub(crate) fn convert_columns( + columns: &[Value], tag: &Tag, ) -> Result<(Vec, Span), ShellError> { let mut col_span = match columns - .iter() - .nth(0) + .get(0) .map(|v| Span::new(v.tag.span.start(), v.tag.span.end())) { Some(span) => span, diff --git a/crates/nu-command/src/commands/dataframe/where_.rs b/crates/nu-command/src/commands/dataframe/where_.rs index cc5094f064..4c8751dc90 100644 --- a/crates/nu-command/src/commands/dataframe/where_.rs +++ b/crates/nu-command/src/commands/dataframe/where_.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use nu_engine::{evaluate_baseline_expr, EvaluatedCommandArgs, WholeStreamCommand}; +use nu_engine::{evaluate_baseline_expr, WholeStreamCommand}; use nu_errors::ShellError; use nu_protocol::{ dataframe::NuDataFrame, @@ -44,7 +44,6 @@ impl WholeStreamCommand for DataFrame { fn command(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let block: CapturedBlock = args.req(0)?; @@ -65,21 +64,21 @@ fn command(args: CommandArgs) -> Result { _ => None, }) }) - .ok_or(ShellError::labeled_error( - "Expected a condition", - "expected a condition", - &tag.span, - ))?; + .ok_or_else(|| { + ShellError::labeled_error("Expected a condition", "expected a condition", &tag.span) + })?; let lhs = match &expression.left.expr { Expression::FullColumnPath(p) => p.as_ref().tail.get(0), _ => None, } - .ok_or(ShellError::labeled_error( - "No column name", - "Not a column name found in left hand side of comparison", - &expression.left.span, - ))?; + .ok_or_else(|| { + ShellError::labeled_error( + "No column name", + "Not a column name found in left hand side of comparison", + &expression.left.span, + ) + })?; let (col_name, col_name_span) = match &lhs.unspanned { UnspannedPathMember::String(name) => Ok((name, &lhs.span)), @@ -90,7 +89,7 @@ fn command(args: CommandArgs) -> Result { )), }?; - let rhs = evaluate_baseline_expr(&expression.right, &args.args.context)?; + let rhs = evaluate_baseline_expr(&expression.right, &args.context)?; filter_dataframe(args, &col_name, &col_name_span, &rhs, &expression.op) } @@ -128,7 +127,7 @@ macro_rules! comparison_arm { // With the information extracted from the block we can filter the dataframe using // polars operations fn filter_dataframe( - mut args: EvaluatedCommandArgs, + mut args: CommandArgs, col_name: &str, col_name_span: &Span, rhs: &Value, @@ -212,6 +211,6 @@ fn filter_dataframe( Ok(OutputStream::one(NuDataFrame::dataframe_to_value( res, - args.call_info.name_tag.clone(), + args.call_info.name_tag, ))) } diff --git a/crates/nu-command/src/commands/dataframe/with_column.rs b/crates/nu-command/src/commands/dataframe/with_column.rs index 394ff80c2d..44911509c6 100644 --- a/crates/nu-command/src/commands/dataframe/with_column.rs +++ b/crates/nu-command/src/commands/dataframe/with_column.rs @@ -40,9 +40,8 @@ impl WholeStreamCommand for DataFrame { } } -fn command(args: CommandArgs) -> Result { +fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let value: Value = args.req(0)?; let name: Tagged = args.req(2)?; diff --git a/crates/nu-command/src/commands/date/format.rs b/crates/nu-command/src/commands/date/format.rs index fccf4fb333..83dba6c93b 100644 --- a/crates/nu-command/src/commands/date/format.rs +++ b/crates/nu-command/src/commands/date/format.rs @@ -44,7 +44,6 @@ impl WholeStreamCommand for Date { pub fn format(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let format: Tagged = args.req(0)?; let table: Option = args.get_flag("table")?; diff --git a/crates/nu-command/src/commands/date/list_timezone.rs b/crates/nu-command/src/commands/date/list_timezone.rs index 91c09866f2..33d53b33bf 100644 --- a/crates/nu-command/src/commands/date/list_timezone.rs +++ b/crates/nu-command/src/commands/date/list_timezone.rs @@ -41,8 +41,7 @@ impl WholeStreamCommand for Date { } fn list_timezone(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let tag = args.call_info.name_tag.clone(); + let tag = args.call_info.name_tag; let list = TZ_VARIANTS.iter().map(move |tz| { let mut entries = IndexMap::new(); diff --git a/crates/nu-command/src/commands/date/now.rs b/crates/nu-command/src/commands/date/now.rs index e97f139664..fda7b596a4 100644 --- a/crates/nu-command/src/commands/date/now.rs +++ b/crates/nu-command/src/commands/date/now.rs @@ -31,8 +31,6 @@ pub fn date_now(tag: &Tag) -> Value { } pub fn now(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let value = date_now(&args.call_info.name_tag); Ok(OutputStream::one(value)) diff --git a/crates/nu-command/src/commands/date/to_table.rs b/crates/nu-command/src/commands/date/to_table.rs index 2261229d4c..aed02a528c 100644 --- a/crates/nu-command/src/commands/date/to_table.rs +++ b/crates/nu-command/src/commands/date/to_table.rs @@ -34,7 +34,6 @@ impl WholeStreamCommand for Date { } fn to_table(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.call_info.name_tag.clone(); let input = if args.input.is_empty() { InputStream::one(crate::commands::date::now::date_now(&tag)) diff --git a/crates/nu-command/src/commands/date/to_timezone.rs b/crates/nu-command/src/commands/date/to_timezone.rs index b093bbda95..056d686df8 100644 --- a/crates/nu-command/src/commands/date/to_timezone.rs +++ b/crates/nu-command/src/commands/date/to_timezone.rs @@ -55,7 +55,6 @@ impl WholeStreamCommand for Date { fn to_timezone(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let timezone: Tagged = args.req(0)?; diff --git a/crates/nu-command/src/commands/debug.rs b/crates/nu-command/src/commands/debug.rs index 3978139e41..68ef3ac977 100644 --- a/crates/nu-command/src/commands/debug.rs +++ b/crates/nu-command/src/commands/debug.rs @@ -24,7 +24,6 @@ impl WholeStreamCommand for Debug { } fn debug_value(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let raw = args.has_flag("raw"); let input = args.input; diff --git a/crates/nu-command/src/commands/default.rs b/crates/nu-command/src/commands/default.rs index f96993447e..a8cdd2aa9d 100644 --- a/crates/nu-command/src/commands/default.rs +++ b/crates/nu-command/src/commands/default.rs @@ -40,7 +40,6 @@ impl WholeStreamCommand for Default { } fn default(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let column: Tagged = args.req(0)?; let value: Value = args.req(1)?; diff --git a/crates/nu-command/src/commands/do_.rs b/crates/nu-command/src/commands/do_.rs index 3a067d28ad..98a1ff8106 100644 --- a/crates/nu-command/src/commands/do_.rs +++ b/crates/nu-command/src/commands/do_.rs @@ -59,11 +59,10 @@ impl WholeStreamCommand for Do { } } -fn do_(raw_args: CommandArgs) -> Result { - let external_redirection = raw_args.call_info.args.external_redirection; +fn do_(args: CommandArgs) -> Result { + let external_redirection = args.call_info.args.external_redirection; - let context = EvaluationContext::from_args(&raw_args); - let args = raw_args.evaluate_once()?; + let context = args.context().clone(); let do_args = DoArgs { block: args.req(0)?, ignore_errors: args.has_flag("ignore-errors"), diff --git a/crates/nu-command/src/commands/drop/column.rs b/crates/nu-command/src/commands/drop/column.rs index 90ba173717..9fdc8b8d06 100644 --- a/crates/nu-command/src/commands/drop/column.rs +++ b/crates/nu-command/src/commands/drop/column.rs @@ -43,7 +43,6 @@ impl WholeStreamCommand for SubCommand { } fn drop(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let columns: Option> = args.opt(0)?; let to_drop = if let Some(quantity) = columns { diff --git a/crates/nu-command/src/commands/drop/command.rs b/crates/nu-command/src/commands/drop/command.rs index 01b575937e..dc6a6156ba 100644 --- a/crates/nu-command/src/commands/drop/command.rs +++ b/crates/nu-command/src/commands/drop/command.rs @@ -47,7 +47,6 @@ impl WholeStreamCommand for Command { } fn drop(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let v: Vec<_> = args.input.into_vec(); diff --git a/crates/nu-command/src/commands/du.rs b/crates/nu-command/src/commands/du.rs index d4bb1a27ab..0d020d781d 100644 --- a/crates/nu-command/src/commands/du.rs +++ b/crates/nu-command/src/commands/du.rs @@ -88,8 +88,6 @@ fn du(args: CommandArgs) -> Result { let ctrl_c = args.ctrl_c(); let ctrl_c_copy = ctrl_c.clone(); - let args = args.evaluate_once()?; - let args = DuArgs { path: args.opt(0)?, all: args.has_flag("all"), diff --git a/crates/nu-command/src/commands/each/command.rs b/crates/nu-command/src/commands/each/command.rs index cb2b5f4c06..c23698df09 100644 --- a/crates/nu-command/src/commands/each/command.rs +++ b/crates/nu-command/src/commands/each/command.rs @@ -114,10 +114,9 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value { dict.into_value() } -fn each(raw_args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&raw_args)); - let external_redirection = raw_args.call_info.args.external_redirection; - let args = raw_args.evaluate_once()?; +fn each(args: CommandArgs) -> Result { + let context = Arc::new(args.context.clone()); + let external_redirection = args.call_info.args.external_redirection; let block: CapturedBlock = args.req(0)?; let numbered: bool = args.has_flag("numbered"); diff --git a/crates/nu-command/src/commands/each/group.rs b/crates/nu-command/src/commands/each/group.rs index a718b5ad8d..6b6eed58d7 100644 --- a/crates/nu-command/src/commands/each/group.rs +++ b/crates/nu-command/src/commands/each/group.rs @@ -37,10 +37,9 @@ impl WholeStreamCommand for EachGroup { }] } - fn run(&self, raw_args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&raw_args)); - let external_redirection = raw_args.call_info.args.external_redirection; - let args = raw_args.evaluate_once()?; + fn run(&self, args: CommandArgs) -> Result { + let context = Arc::new(args.context.clone()); + let external_redirection = args.call_info.args.external_redirection; let group_size: Tagged = args.req(0)?; let block: CapturedBlock = args.req(1)?; diff --git a/crates/nu-command/src/commands/each/window.rs b/crates/nu-command/src/commands/each/window.rs index bc412705ab..f8889acbe5 100644 --- a/crates/nu-command/src/commands/each/window.rs +++ b/crates/nu-command/src/commands/each/window.rs @@ -41,11 +41,10 @@ impl WholeStreamCommand for EachWindow { }] } - fn run(&self, raw_args: CommandArgs) -> Result { - let context = Arc::new(EvaluationContext::from_args(&raw_args)); - let external_redirection = raw_args.call_info.args.external_redirection; + fn run(&self, mut args: CommandArgs) -> Result { + let context = Arc::new(EvaluationContext::from_args(&args)); + let external_redirection = args.call_info.args.external_redirection; - let mut args = raw_args.evaluate_once()?; let window_size: Tagged = args.req(0)?; let block: CapturedBlock = args.req(1)?; let stride: Option> = args.get_flag("stride")?; diff --git a/crates/nu-command/src/commands/echo.rs b/crates/nu-command/src/commands/echo.rs index 65dabdbecc..34d20e8227 100644 --- a/crates/nu-command/src/commands/echo.rs +++ b/crates/nu-command/src/commands/echo.rs @@ -54,7 +54,6 @@ pub fn expand_value_to_stream(v: Value) -> InputStream { } fn echo(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let stream = rest.into_iter().map(|i| match i.as_string() { diff --git a/crates/nu-command/src/commands/empty.rs b/crates/nu-command/src/commands/empty.rs index 958d712727..ecba53758c 100644 --- a/crates/nu-command/src/commands/empty.rs +++ b/crates/nu-command/src/commands/empty.rs @@ -84,7 +84,6 @@ 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 args = args.evaluate_once()?; let block: Option = args.get_flag("block")?; let columns: Vec = args.rest(0)?; diff --git a/crates/nu-command/src/commands/enter.rs b/crates/nu-command/src/commands/enter.rs index ba827cfed5..5755ffa63b 100644 --- a/crates/nu-command/src/commands/enter.rs +++ b/crates/nu-command/src/commands/enter.rs @@ -74,7 +74,6 @@ fn enter(args: CommandArgs) -> Result { let context = args.context.clone(); let scope = args.scope().clone(); let path = args.context.shell_manager.path(); - let args = args.evaluate_once()?; let location: Tagged = args.req(0)?; let encoding: Option> = args.get_flag("encoding")?; diff --git a/crates/nu-command/src/commands/every.rs b/crates/nu-command/src/commands/every.rs index 9728c40c6d..b1ffd46b03 100644 --- a/crates/nu-command/src/commands/every.rs +++ b/crates/nu-command/src/commands/every.rs @@ -56,8 +56,6 @@ impl WholeStreamCommand for Every { } fn every(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let stride: u64 = args.req(0)?; let skip: bool = args.has_flag("skip"); let input = args.input; diff --git a/crates/nu-command/src/commands/exec.rs b/crates/nu-command/src/commands/exec.rs index e2de15baab..f715d2b0b5 100644 --- a/crates/nu-command/src/commands/exec.rs +++ b/crates/nu-command/src/commands/exec.rs @@ -64,7 +64,6 @@ fn exec(args: CommandArgs) -> Result { use std::process::Command; let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let args = ExecArgs { command: args.req(0)?, diff --git a/crates/nu-command/src/commands/exit.rs b/crates/nu-command/src/commands/exit.rs index 0b7435ba5b..cc6754d156 100644 --- a/crates/nu-command/src/commands/exit.rs +++ b/crates/nu-command/src/commands/exit.rs @@ -44,15 +44,13 @@ impl WholeStreamCommand for Exit { } pub fn exit(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - - let code = if let Some(value) = args.call_info.args.nth(0) { - value.as_i32()? + let code = if let Some(value) = args.opt::(0)? { + value as i32 } else { 0 }; - let command_action = if args.call_info.args.has("now") { + let command_action = if args.has_flag("now") { CommandAction::Exit(code) } else { CommandAction::LeaveShell(code) diff --git a/crates/nu-command/src/commands/first.rs b/crates/nu-command/src/commands/first.rs index a93814faf3..97514a727b 100644 --- a/crates/nu-command/src/commands/first.rs +++ b/crates/nu-command/src/commands/first.rs @@ -47,7 +47,6 @@ impl WholeStreamCommand for First { } fn first(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/flatten.rs b/crates/nu-command/src/commands/flatten.rs index 92506a1a65..e0f3618dc2 100644 --- a/crates/nu-command/src/commands/flatten.rs +++ b/crates/nu-command/src/commands/flatten.rs @@ -48,7 +48,6 @@ impl WholeStreamCommand for Command { fn flatten(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let columns: Vec> = args.rest(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/for_in.rs b/crates/nu-command/src/commands/for_in.rs index eb6f1cdcf2..46a798ea79 100644 --- a/crates/nu-command/src/commands/for_in.rs +++ b/crates/nu-command/src/commands/for_in.rs @@ -111,8 +111,7 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> 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; - //let args = raw_args.evaluate_once()?; - + // let numbered: bool = raw_args.call_info.switch_present("numbered"); let positional = raw_args .call_info diff --git a/crates/nu-command/src/commands/format/command.rs b/crates/nu-command/src/commands/format/command.rs index ff42dadd19..d10c20e88b 100644 --- a/crates/nu-command/src/commands/format/command.rs +++ b/crates/nu-command/src/commands/format/command.rs @@ -40,7 +40,6 @@ impl WholeStreamCommand for Format { fn format_command(args: CommandArgs) -> Result { let ctx = Arc::new(EvaluationContext::from_args(&args)); - let args = args.evaluate_once()?; let pattern: Tagged = args.req(0)?; let format_pattern = format(&pattern); diff --git a/crates/nu-command/src/commands/format/format_filesize.rs b/crates/nu-command/src/commands/format/format_filesize.rs index 2f19477226..9748a82e13 100644 --- a/crates/nu-command/src/commands/format/format_filesize.rs +++ b/crates/nu-command/src/commands/format/format_filesize.rs @@ -83,9 +83,7 @@ fn process_row( } } -fn filesize(raw_args: CommandArgs) -> Result { - let args = raw_args.evaluate_once()?; - +fn filesize(args: CommandArgs) -> Result { let field: ColumnPath = args.req(0)?; let format: Tagged = args.req(1)?; let field = Arc::new(field); diff --git a/crates/nu-command/src/commands/from_csv.rs b/crates/nu-command/src/commands/from_csv.rs index d15e19ee62..72d8ab14ec 100644 --- a/crates/nu-command/src/commands/from_csv.rs +++ b/crates/nu-command/src/commands/from_csv.rs @@ -62,7 +62,6 @@ impl WholeStreamCommand for FromCsv { fn from_csv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let noheaders = args.has_flag("noheaders"); let separator: Option = args.get_flag("separator")?; diff --git a/crates/nu-command/src/commands/from_eml.rs b/crates/nu-command/src/commands/from_eml.rs index 818f88491b..cd2de742f5 100644 --- a/crates/nu-command/src/commands/from_eml.rs +++ b/crates/nu-command/src/commands/from_eml.rs @@ -68,7 +68,6 @@ fn headerfieldvalue_to_value(tag: &Tag, value: &HeaderFieldValue) -> UntaggedVal fn from_eml(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let preview_body: Option> = args.get_flag("preview-body")?; diff --git a/crates/nu-command/src/commands/from_ics.rs b/crates/nu-command/src/commands/from_ics.rs index 8d13b16432..df90cc22f8 100644 --- a/crates/nu-command/src/commands/from_ics.rs +++ b/crates/nu-command/src/commands/from_ics.rs @@ -28,7 +28,6 @@ impl WholeStreamCommand for FromIcs { } fn from_ics(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/from_ini.rs b/crates/nu-command/src/commands/from_ini.rs index 960a7e78cf..0fa55bddef 100644 --- a/crates/nu-command/src/commands/from_ini.rs +++ b/crates/nu-command/src/commands/from_ini.rs @@ -60,7 +60,6 @@ pub fn from_ini_string_to_value( } fn from_ini(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; let concat_string = input.collect_string(tag.clone())?; diff --git a/crates/nu-command/src/commands/from_json.rs b/crates/nu-command/src/commands/from_json.rs index d48936f756..5bc4bb5bcf 100644 --- a/crates/nu-command/src/commands/from_json.rs +++ b/crates/nu-command/src/commands/from_json.rs @@ -65,7 +65,6 @@ pub fn from_json_string_to_value(s: String, tag: impl Into) -> nu_json::Res fn from_json(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let objects = args.has_flag("objects"); let concat_string = args.input.collect_string(name_tag.clone())?; diff --git a/crates/nu-command/src/commands/from_ods.rs b/crates/nu-command/src/commands/from_ods.rs index f8cf3c705a..5187d5f082 100644 --- a/crates/nu-command/src/commands/from_ods.rs +++ b/crates/nu-command/src/commands/from_ods.rs @@ -52,14 +52,10 @@ fn from_ods(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let span = tag.span; - let args = args.evaluate_once()?; - let mut sel_sheets = vec![]; - if let Some(s) = args.call_info.args.get("sheets") { - if let UntaggedValue::Table(columns) = s.value.clone() { - sel_sheets = convert_columns(columns.as_slice())?; - } + if let Some(columns) = args.get_flag::>("sheets")? { + sel_sheets = convert_columns(columns.as_slice())?; } let bytes = args.input.collect_binary(tag.clone())?; diff --git a/crates/nu-command/src/commands/from_ssv.rs b/crates/nu-command/src/commands/from_ssv.rs index 7d477210fa..7931524eb4 100644 --- a/crates/nu-command/src/commands/from_ssv.rs +++ b/crates/nu-command/src/commands/from_ssv.rs @@ -237,7 +237,6 @@ fn from_ssv_string_to_value( fn from_ssv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let noheaders = args.has_flag("noheaders"); let aligned_columns = args.has_flag("aligned-columns"); diff --git a/crates/nu-command/src/commands/from_toml.rs b/crates/nu-command/src/commands/from_toml.rs index 872f4680f2..009ae82070 100644 --- a/crates/nu-command/src/commands/from_toml.rs +++ b/crates/nu-command/src/commands/from_toml.rs @@ -61,7 +61,6 @@ pub fn from_toml_string_to_value(s: String, tag: impl Into) -> Result Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/from_tsv.rs b/crates/nu-command/src/commands/from_tsv.rs index da63836e5b..c5380bdfe3 100644 --- a/crates/nu-command/src/commands/from_tsv.rs +++ b/crates/nu-command/src/commands/from_tsv.rs @@ -30,7 +30,6 @@ impl WholeStreamCommand for FromTsv { fn from_tsv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let noheaders = args.has_flag("noheaders"); let input = args.input; diff --git a/crates/nu-command/src/commands/from_url.rs b/crates/nu-command/src/commands/from_url.rs index 7953b02612..f3c9e9bace 100644 --- a/crates/nu-command/src/commands/from_url.rs +++ b/crates/nu-command/src/commands/from_url.rs @@ -24,7 +24,6 @@ impl WholeStreamCommand for FromUrl { } fn from_url(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/from_vcf.rs b/crates/nu-command/src/commands/from_vcf.rs index c628da53cb..5ff42a071c 100644 --- a/crates/nu-command/src/commands/from_vcf.rs +++ b/crates/nu-command/src/commands/from_vcf.rs @@ -26,7 +26,6 @@ impl WholeStreamCommand for FromVcf { } fn from_vcf(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/from_xlsx.rs b/crates/nu-command/src/commands/from_xlsx.rs index df037f8900..0bf2c0d6bb 100644 --- a/crates/nu-command/src/commands/from_xlsx.rs +++ b/crates/nu-command/src/commands/from_xlsx.rs @@ -58,14 +58,10 @@ fn from_xlsx(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let span = tag.span; - let args = args.evaluate_once()?; - let mut sel_sheets = vec![]; - if let Some(s) = args.call_info.args.get("sheets") { - if let UntaggedValue::Table(columns) = s.value.clone() { - sel_sheets = convert_columns(columns.as_slice())?; - } + if let Some(columns) = args.get_flag::>("sheets")? { + sel_sheets = convert_columns(columns.as_slice())?; } let value = args.input.collect_binary(tag.clone())?; diff --git a/crates/nu-command/src/commands/from_xml.rs b/crates/nu-command/src/commands/from_xml.rs index f975b54ed4..7f7e8ed7d0 100644 --- a/crates/nu-command/src/commands/from_xml.rs +++ b/crates/nu-command/src/commands/from_xml.rs @@ -95,7 +95,6 @@ pub fn from_xml_string_to_value(s: String, tag: impl Into) -> Result Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/from_yaml.rs b/crates/nu-command/src/commands/from_yaml.rs index 80267bb772..6a53d40b71 100644 --- a/crates/nu-command/src/commands/from_yaml.rs +++ b/crates/nu-command/src/commands/from_yaml.rs @@ -132,7 +132,6 @@ pub fn from_yaml_string_to_value(s: String, tag: impl Into) -> Result Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/get.rs b/crates/nu-command/src/commands/get.rs index 74caaa0a9c..5e47ac8605 100644 --- a/crates/nu-command/src/commands/get.rs +++ b/crates/nu-command/src/commands/get.rs @@ -49,7 +49,6 @@ impl WholeStreamCommand for Command { } pub fn get(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let column_paths: Vec = args.rest(0)?; let mut input = args.input; diff --git a/crates/nu-command/src/commands/group_by.rs b/crates/nu-command/src/commands/group_by.rs index 8481bd5feb..746aaece16 100644 --- a/crates/nu-command/src/commands/group_by.rs +++ b/crates/nu-command/src/commands/group_by.rs @@ -126,7 +126,6 @@ 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 args = args.evaluate_once()?; let grouper = args.opt(0)?; let values: Vec = args.input.collect(); diff --git a/crates/nu-command/src/commands/group_by_date.rs b/crates/nu-command/src/commands/group_by_date.rs index 84144ea38e..3787f3f1d5 100644 --- a/crates/nu-command/src/commands/group_by_date.rs +++ b/crates/nu-command/src/commands/group_by_date.rs @@ -54,7 +54,6 @@ enum GroupByColumn { pub fn group_by_date(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let column_name: Option> = args.opt(0)?; let format: Option> = args.get_flag("format")?; diff --git a/crates/nu-command/src/commands/hash_/base64_.rs b/crates/nu-command/src/commands/hash_/base64_.rs index d0feeeaca5..4fd4a9e9c0 100644 --- a/crates/nu-command/src/commands/hash_/base64_.rs +++ b/crates/nu-command/src/commands/hash_/base64_.rs @@ -87,7 +87,6 @@ impl WholeStreamCommand for SubCommand { fn operate(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let encode = args.has_flag("encode"); let decode = args.has_flag("decode"); diff --git a/crates/nu-command/src/commands/hash_/md5_.rs b/crates/nu-command/src/commands/hash_/md5_.rs index e3eab879dc..b70974e084 100644 --- a/crates/nu-command/src/commands/hash_/md5_.rs +++ b/crates/nu-command/src/commands/hash_/md5_.rs @@ -50,7 +50,6 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let column_paths: Vec = args.rest(0)?; Ok(args diff --git a/crates/nu-command/src/commands/help.rs b/crates/nu-command/src/commands/help.rs index 60a2aa8cff..509fc4f8ba 100644 --- a/crates/nu-command/src/commands/help.rs +++ b/crates/nu-command/src/commands/help.rs @@ -34,7 +34,6 @@ impl WholeStreamCommand for Help { fn help(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let scope = args.scope().clone(); - let args = args.evaluate_once()?; let rest: Vec> = args.rest(0)?; diff --git a/crates/nu-command/src/commands/histogram.rs b/crates/nu-command/src/commands/histogram.rs index 1d64554082..8b113a325e 100644 --- a/crates/nu-command/src/commands/histogram.rs +++ b/crates/nu-command/src/commands/histogram.rs @@ -59,21 +59,10 @@ impl WholeStreamCommand for Histogram { pub fn histogram(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let (input, args) = args.evaluate_once()?.parts(); - let values: Vec = input.collect(); - - let mut columns = args - .positional_iter() - .map(|c| c.as_column_path()) - .filter_map(Result::ok) - .collect::>(); - - let evaluate_with = if let Some(path) = args.get("use") { - Some(evaluator(path.as_column_path()?.item)) - } else { - None - }; + let mut columns = args.rest::(0)?; + let evaluate_with = args.get_flag::("use")?.map(evaluator); + let values: Vec = args.input.collect(); let column_grouper = if !columns.is_empty() { columns diff --git a/crates/nu-command/src/commands/history.rs b/crates/nu-command/src/commands/history.rs index 981c458357..74c30f4dd1 100644 --- a/crates/nu-command/src/commands/history.rs +++ b/crates/nu-command/src/commands/history.rs @@ -28,7 +28,6 @@ impl WholeStreamCommand for History { fn history(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let args = args.evaluate_once()?; let clear = args.has_flag("clear"); diff --git a/crates/nu-command/src/commands/if_.rs b/crates/nu-command/src/commands/if_.rs index bfd37dcf71..70a2936232 100644 --- a/crates/nu-command/src/commands/if_.rs +++ b/crates/nu-command/src/commands/if_.rs @@ -57,12 +57,11 @@ impl WholeStreamCommand for If { ] } } -fn if_command(raw_args: CommandArgs) -> Result { - let tag = raw_args.call_info.name_tag.clone(); - let external_redirection = raw_args.call_info.args.external_redirection; - let context = Arc::new(EvaluationContext::from_args(&raw_args)); +fn if_command(args: CommandArgs) -> Result { + let tag = args.call_info.name_tag.clone(); + let external_redirection = args.call_info.args.external_redirection; + let context = Arc::new(args.context.clone()); - let args = raw_args.evaluate_once()?; let condition: CapturedBlock = args.req(0)?; let then_case: CapturedBlock = args.req(1)?; let else_case: CapturedBlock = args.req(2)?; diff --git a/crates/nu-command/src/commands/insert.rs b/crates/nu-command/src/commands/insert.rs index b933d6c964..39c7ea1bdc 100644 --- a/crates/nu-command/src/commands/insert.rs +++ b/crates/nu-command/src/commands/insert.rs @@ -154,7 +154,6 @@ fn process_row( fn insert(args: CommandArgs) -> Result { let context = Arc::new(EvaluationContext::from_args(&args)); - let args = args.evaluate_once()?; let column: ColumnPath = args.req(0)?; let value: Value = args.req(1)?; let input = args.input; diff --git a/crates/nu-command/src/commands/into/binary.rs b/crates/nu-command/src/commands/into/binary.rs index 7dd3393664..3466c4fede 100644 --- a/crates/nu-command/src/commands/into/binary.rs +++ b/crates/nu-command/src/commands/into/binary.rs @@ -113,7 +113,6 @@ impl WholeStreamCommand for SubCommand { } fn into_binary(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let skip: Option = args.get_flag("skip")?; let bytes: Option = args.get_flag("bytes")?; let column_paths: Vec = args.rest(0)?; diff --git a/crates/nu-command/src/commands/into/int.rs b/crates/nu-command/src/commands/into/int.rs index 7a4c10f2f8..ff63724b40 100644 --- a/crates/nu-command/src/commands/into/int.rs +++ b/crates/nu-command/src/commands/into/int.rs @@ -79,7 +79,6 @@ impl WholeStreamCommand for SubCommand { } fn into_int(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let column_paths: Vec = args.rest(0)?; Ok(args diff --git a/crates/nu-command/src/commands/into/string.rs b/crates/nu-command/src/commands/into/string.rs index e7de1da013..cbbc888676 100644 --- a/crates/nu-command/src/commands/into/string.rs +++ b/crates/nu-command/src/commands/into/string.rs @@ -81,8 +81,6 @@ impl WholeStreamCommand for SubCommand { } fn into_string(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let decimals: Option> = args.get_flag("decimals")?; let column_paths: Vec = args.rest(0)?; diff --git a/crates/nu-command/src/commands/keep/command.rs b/crates/nu-command/src/commands/keep/command.rs index b78a327aea..fa4652bfc0 100644 --- a/crates/nu-command/src/commands/keep/command.rs +++ b/crates/nu-command/src/commands/keep/command.rs @@ -49,7 +49,6 @@ impl WholeStreamCommand for Command { } fn keep(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let rows_desired = if let Some(quantity) = rows { diff --git a/crates/nu-command/src/commands/keep/until.rs b/crates/nu-command/src/commands/keep/until.rs index 811974f0f7..c0e789853e 100644 --- a/crates/nu-command/src/commands/keep/until.rs +++ b/crates/nu-command/src/commands/keep/until.rs @@ -33,9 +33,7 @@ impl WholeStreamCommand for SubCommand { let ctx = Arc::new(EvaluationContext::from_args(&args)); let tag = args.call_info.name_tag.clone(); - let call_info = args.evaluate_once()?; - - let block: CapturedBlock = call_info.req(0)?; + let block: CapturedBlock = args.req(0)?; let condition = { if block.block.block.len() != 1 { return Err(ShellError::labeled_error( @@ -65,7 +63,7 @@ impl WholeStreamCommand for SubCommand { } }; - Ok(call_info + Ok(args .input .take_while(move |item| { let condition = condition.clone(); diff --git a/crates/nu-command/src/commands/keep/while_.rs b/crates/nu-command/src/commands/keep/while_.rs index a60419ddfb..ecd703b5cb 100644 --- a/crates/nu-command/src/commands/keep/while_.rs +++ b/crates/nu-command/src/commands/keep/while_.rs @@ -32,9 +32,8 @@ impl WholeStreamCommand for SubCommand { fn run(&self, args: CommandArgs) -> Result { let ctx = Arc::new(EvaluationContext::from_args(&args)); let tag = args.call_info.name_tag.clone(); - let call_info = args.evaluate_once()?; - let block: CapturedBlock = call_info.req(0)?; + let block: CapturedBlock = args.req(0)?; let condition = { if block.block.block.len() != 1 { return Err(ShellError::labeled_error( @@ -64,7 +63,7 @@ impl WholeStreamCommand for SubCommand { } }; - Ok(call_info + Ok(args .input .take_while(move |item| { let condition = condition.clone(); diff --git a/crates/nu-command/src/commands/kill.rs b/crates/nu-command/src/commands/kill.rs index c1bc955d44..9e15af787c 100644 --- a/crates/nu-command/src/commands/kill.rs +++ b/crates/nu-command/src/commands/kill.rs @@ -65,8 +65,6 @@ impl WholeStreamCommand for Kill { } fn kill(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let pid: Tagged = args.req(0)?; let rest: Vec> = args.rest(1)?; let force: Option> = args.get_flag("force")?; diff --git a/crates/nu-command/src/commands/last.rs b/crates/nu-command/src/commands/last.rs index 65ccea5047..b7a035b34c 100644 --- a/crates/nu-command/src/commands/last.rs +++ b/crates/nu-command/src/commands/last.rs @@ -47,12 +47,11 @@ impl WholeStreamCommand for Last { } fn last(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let rows = args.nth(0).cloned(); + let rows: Option = args.opt(0)?; let v: Vec<_> = args.input.into_vec(); let end_rows_desired = if let Some(quantity) = rows { - quantity.as_usize()? + quantity } else { 1 }; diff --git a/crates/nu-command/src/commands/length.rs b/crates/nu-command/src/commands/length.rs index 7f6ca491d7..2e63f45e9a 100644 --- a/crates/nu-command/src/commands/length.rs +++ b/crates/nu-command/src/commands/length.rs @@ -25,7 +25,6 @@ impl WholeStreamCommand for Length { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let column = args.has_flag("column"); let input = args.input; diff --git a/crates/nu-command/src/commands/let_env.rs b/crates/nu-command/src/commands/let_env.rs index 0e4ff670b7..9da1988c17 100644 --- a/crates/nu-command/src/commands/let_env.rs +++ b/crates/nu-command/src/commands/let_env.rs @@ -51,8 +51,6 @@ pub fn set_env(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let args = args.evaluate_once()?; - let name: Tagged = args.req(0)?; let rhs: CapturedBlock = args.req(2)?; diff --git a/crates/nu-command/src/commands/lines.rs b/crates/nu-command/src/commands/lines.rs index fd5529c528..27bd61c5a9 100644 --- a/crates/nu-command/src/commands/lines.rs +++ b/crates/nu-command/src/commands/lines.rs @@ -44,7 +44,6 @@ fn ends_with_line_ending(st: &str) -> bool { fn lines(args: CommandArgs) -> Result { let leftover_string = Arc::new(Mutex::new(String::new())); - let args = args.evaluate_once()?; let tag = args.name_tag(); let name_span = tag.span; diff --git a/crates/nu-command/src/commands/load_env.rs b/crates/nu-command/src/commands/load_env.rs index d991791c7c..fa5eaade5a 100644 --- a/crates/nu-command/src/commands/load_env.rs +++ b/crates/nu-command/src/commands/load_env.rs @@ -83,7 +83,6 @@ fn load_env_from_table( pub fn load_env(args: CommandArgs) -> Result { let ctx = EvaluationContext::from_args(&args); - let args = args.evaluate_once()?; if let Some(values) = args.opt::>(0)? { load_env_from_table(values, &ctx)?; diff --git a/crates/nu-command/src/commands/ls.rs b/crates/nu-command/src/commands/ls.rs index 5ec270adea..23ac1e6591 100644 --- a/crates/nu-command/src/commands/ls.rs +++ b/crates/nu-command/src/commands/ls.rs @@ -43,7 +43,6 @@ impl WholeStreamCommand for Ls { let name = args.call_info.name_tag.clone(); let ctrl_c = args.ctrl_c(); let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; let args = LsArgs { path: args.opt(0)?, diff --git a/crates/nu-command/src/commands/macros.rs b/crates/nu-command/src/commands/macros.rs deleted file mode 100644 index cf89796dbe..0000000000 --- a/crates/nu-command/src/commands/macros.rs +++ /dev/null @@ -1,351 +0,0 @@ -// #[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 ) )* -// } - -// 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; - -// Ok(output.to_action_stream()) -// } - -// let $args = $args.evaluate_once(registry)?; -// let tuple = ( $($extract ,)* ); -// command( $args, tuple ) -// } - -// 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, - -// named: { -// use $nu_parser::registry::NamedType; - -// #[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 -// } -// } -// } -// } -// }; - -// // 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) -// } - -// Extract { -// $($extract)* { -// use std::convert::TryInto; - -// $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)) -// } -// } - -// Function { -// $($function)* ($param_name : $param_kind) -// } - -// Extract { -// $($extract)* { -// use std::convert::TryInto; - -// $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)) -// } -// } - -// Function { -// $($function)* ($param_name : $param_kind) -// } - -// Extract { -// $($extract)* { -// use std::convert::TryInto; - -// $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)* -// } -// } - -// 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)* $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) -// } - -// 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)* -// } -// } - -// 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)* $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) -// } - -// 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: {} -// } - -// Function { -// } - -// Extract { -// } -// ); -// }; -// } diff --git a/crates/nu-command/src/commands/math/eval.rs b/crates/nu-command/src/commands/math/eval.rs index dda7c6212e..679358fa15 100644 --- a/crates/nu-command/src/commands/math/eval.rs +++ b/crates/nu-command/src/commands/math/eval.rs @@ -41,7 +41,6 @@ impl WholeStreamCommand for SubCommand { } pub fn eval(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let expression: Option> = args.opt(0)?; let name = args.call_info.name_tag.clone(); let input = args.input; diff --git a/crates/nu-command/src/commands/math/round.rs b/crates/nu-command/src/commands/math/round.rs index 1ce68450ca..b0f19a2b6d 100644 --- a/crates/nu-command/src/commands/math/round.rs +++ b/crates/nu-command/src/commands/math/round.rs @@ -53,7 +53,6 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let precision: Option> = args.get_flag("precision")?; let input = args.input; let precision = if let Some(precision) = precision { diff --git a/crates/nu-command/src/commands/math/stddev.rs b/crates/nu-command/src/commands/math/stddev.rs index c979f7d70a..7048a45ea8 100644 --- a/crates/nu-command/src/commands/math/stddev.rs +++ b/crates/nu-command/src/commands/math/stddev.rs @@ -24,12 +24,10 @@ impl WholeStreamCommand for SubCommand { "Finds the stddev of a list of numbers or tables" } - fn run(&self, raw_args: CommandArgs) -> Result { - let mut args = raw_args.evaluate_once()?; - + fn run(&self, mut args: CommandArgs) -> Result { let sample: bool = args.has_flag("sample"); let values: Vec = args.input.drain_vec(); - let name = args.call_info.name_tag.clone(); + let name = args.call_info.name_tag; let n = if sample { values.len() - 1 diff --git a/crates/nu-command/src/commands/math/variance.rs b/crates/nu-command/src/commands/math/variance.rs index f68702a75f..92b80a65f4 100644 --- a/crates/nu-command/src/commands/math/variance.rs +++ b/crates/nu-command/src/commands/math/variance.rs @@ -20,12 +20,10 @@ impl WholeStreamCommand for SubCommand { "Finds the variance of a list of numbers or tables" } - fn run(&self, raw_args: CommandArgs) -> Result { - let mut args = raw_args.evaluate_once()?; - + fn run(&self, mut args: CommandArgs) -> Result { let sample: bool = args.has_flag("sample"); let values: Vec = args.input.drain_vec(); - let name = args.call_info.name_tag.clone(); + let name = args.call_info.name_tag; let n = if sample { values.len() - 1 diff --git a/crates/nu-command/src/commands/merge.rs b/crates/nu-command/src/commands/merge.rs index 335b22d92c..42633ef716 100644 --- a/crates/nu-command/src/commands/merge.rs +++ b/crates/nu-command/src/commands/merge.rs @@ -45,7 +45,6 @@ fn merge(args: CommandArgs) -> Result { let context = EvaluationContext::from_args(&args); let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let block: CapturedBlock = args.req(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/mkdir.rs b/crates/nu-command/src/commands/mkdir.rs index 7a1733c237..55770f62ac 100644 --- a/crates/nu-command/src/commands/mkdir.rs +++ b/crates/nu-command/src/commands/mkdir.rs @@ -39,7 +39,6 @@ fn mkdir(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; let args = MkdirArgs { rest: args.rest(0)?, show_created_paths: args.has_flag("show-created-paths"), diff --git a/crates/nu-command/src/commands/move_/command.rs b/crates/nu-command/src/commands/move_/command.rs index ebce46bc74..9c8a58c681 100644 --- a/crates/nu-command/src/commands/move_/command.rs +++ b/crates/nu-command/src/commands/move_/command.rs @@ -75,9 +75,8 @@ impl WholeStreamCommand for Command { } } -fn operate(raw_args: CommandArgs) -> Result { - let name = raw_args.call_info.name_tag.clone(); - let args = raw_args.evaluate_once()?; +fn operate(args: CommandArgs) -> Result { + let name = args.call_info.name_tag.clone(); let mut columns: Vec = args.rest(0)?; let before: Option = args.get_flag("before")?; diff --git a/crates/nu-command/src/commands/move_/mv.rs b/crates/nu-command/src/commands/move_/mv.rs index 82ba1ad147..b38178d139 100644 --- a/crates/nu-command/src/commands/move_/mv.rs +++ b/crates/nu-command/src/commands/move_/mv.rs @@ -57,7 +57,6 @@ fn mv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; let args = MvArgs { src: args.req(0)?, dst: args.req(1)?, diff --git a/crates/nu-command/src/commands/nth.rs b/crates/nu-command/src/commands/nth.rs index 31f9b9ee12..0d460a65cf 100644 --- a/crates/nu-command/src/commands/nth.rs +++ b/crates/nu-command/src/commands/nth.rs @@ -52,8 +52,6 @@ impl WholeStreamCommand for Nth { } fn nth(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let row_number: Tagged = args.req(0)?; let and_rows: Vec> = args.rest(1)?; let skip = args.has_flag("skip"); diff --git a/crates/nu-command/src/commands/nu/plugin.rs b/crates/nu-command/src/commands/nu/plugin.rs index 6687793172..35bee3b377 100644 --- a/crates/nu-command/src/commands/nu/plugin.rs +++ b/crates/nu-command/src/commands/nu/plugin.rs @@ -49,8 +49,6 @@ impl WholeStreamCommand for SubCommand { let scope = args.scope().clone(); let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; - let load_path: Option> = args.get_flag("load")?; if let Some(Tagged { diff --git a/crates/nu-command/src/commands/open.rs b/crates/nu-command/src/commands/open.rs index 11e19775a4..ac1d7edb80 100644 --- a/crates/nu-command/src/commands/open.rs +++ b/crates/nu-command/src/commands/open.rs @@ -99,7 +99,6 @@ fn open(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let ctrl_c = args.ctrl_c(); - let args = args.evaluate_once()?; let path: Tagged = args.req(0)?; let raw = args.has_flag("raw"); let encoding: Option> = args.get_flag("encoding")?; diff --git a/crates/nu-command/src/commands/parse/command.rs b/crates/nu-command/src/commands/parse/command.rs index aa4dea5d27..5331481388 100644 --- a/crates/nu-command/src/commands/parse/command.rs +++ b/crates/nu-command/src/commands/parse/command.rs @@ -52,7 +52,6 @@ impl WholeStreamCommand for Command { pub fn operate(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let pattern: Tagged = args.req(0)?; let regex: bool = args.has_flag("regex"); diff --git a/crates/nu-command/src/commands/path/basename.rs b/crates/nu-command/src/commands/path/basename.rs index 101259f3bd..fcdf0712f0 100644 --- a/crates/nu-command/src/commands/path/basename.rs +++ b/crates/nu-command/src/commands/path/basename.rs @@ -41,7 +41,6 @@ impl WholeStreamCommand for PathBasename { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathBasenameArguments { rest: args.rest(0)?, replace: args.get_flag("replace")?, diff --git a/crates/nu-command/src/commands/path/dirname.rs b/crates/nu-command/src/commands/path/dirname.rs index 881daf84a8..af303b47a8 100644 --- a/crates/nu-command/src/commands/path/dirname.rs +++ b/crates/nu-command/src/commands/path/dirname.rs @@ -48,7 +48,6 @@ impl WholeStreamCommand for PathDirname { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathDirnameArguments { rest: args.rest(0)?, replace: args.get_flag("replace")?, diff --git a/crates/nu-command/src/commands/path/exists.rs b/crates/nu-command/src/commands/path/exists.rs index 12a94e049e..6526030871 100644 --- a/crates/nu-command/src/commands/path/exists.rs +++ b/crates/nu-command/src/commands/path/exists.rs @@ -33,7 +33,6 @@ impl WholeStreamCommand for PathExists { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathExistsArguments { rest: args.rest(0)?, }); diff --git a/crates/nu-command/src/commands/path/expand.rs b/crates/nu-command/src/commands/path/expand.rs index 41d22c02b2..9298c8a291 100644 --- a/crates/nu-command/src/commands/path/expand.rs +++ b/crates/nu-command/src/commands/path/expand.rs @@ -43,7 +43,6 @@ impl WholeStreamCommand for PathExpand { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathExpandArguments { strict: args.has_flag("strict"), rest: args.rest(0)?, diff --git a/crates/nu-command/src/commands/path/join.rs b/crates/nu-command/src/commands/path/join.rs index 0d8b50bfa7..957949e9b5 100644 --- a/crates/nu-command/src/commands/path/join.rs +++ b/crates/nu-command/src/commands/path/join.rs @@ -46,7 +46,6 @@ the output of 'path parse' and 'path split' subcommands."# fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathJoinArguments { rest: args.rest(0)?, append: args.get_flag("append")?, diff --git a/crates/nu-command/src/commands/path/parse.rs b/crates/nu-command/src/commands/path/parse.rs index 3388148ba5..9464473018 100644 --- a/crates/nu-command/src/commands/path/parse.rs +++ b/crates/nu-command/src/commands/path/parse.rs @@ -48,7 +48,6 @@ On Windows, an extra 'prefix' column is added."# fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathParseArguments { rest: args.rest(0)?, extension: args.get_flag("extension")?, diff --git a/crates/nu-command/src/commands/path/relative_to.rs b/crates/nu-command/src/commands/path/relative_to.rs index 7cf9c91d22..ee99481d00 100644 --- a/crates/nu-command/src/commands/path/relative_to.rs +++ b/crates/nu-command/src/commands/path/relative_to.rs @@ -46,7 +46,6 @@ path."# fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathRelativeToArguments { path: args.req(0)?, rest: args.rest(1)?, diff --git a/crates/nu-command/src/commands/path/split.rs b/crates/nu-command/src/commands/path/split.rs index fac4a96f23..9bb0e1920c 100644 --- a/crates/nu-command/src/commands/path/split.rs +++ b/crates/nu-command/src/commands/path/split.rs @@ -33,7 +33,6 @@ impl WholeStreamCommand for PathSplit { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathSplitArguments { rest: args.rest(0)?, }); diff --git a/crates/nu-command/src/commands/path/type.rs b/crates/nu-command/src/commands/path/type.rs index 58767fb4f1..f5a0f78e42 100644 --- a/crates/nu-command/src/commands/path/type.rs +++ b/crates/nu-command/src/commands/path/type.rs @@ -34,7 +34,6 @@ impl WholeStreamCommand for PathType { fn run(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = Arc::new(PathTypeArguments { rest: args.rest(0)?, }); diff --git a/crates/nu-command/src/commands/pivot.rs b/crates/nu-command/src/commands/pivot.rs index 84aa6e0d38..6b0879dbfd 100644 --- a/crates/nu-command/src/commands/pivot.rs +++ b/crates/nu-command/src/commands/pivot.rs @@ -53,7 +53,6 @@ impl WholeStreamCommand for Pivot { pub fn pivot(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); //let (args, input): (PivotArgs, _) = args.process()?; - let args = args.evaluate_once()?; let pivot_args = PivotArgs { header_row: args.has_flag("header-row"), ignore_titles: args.has_flag("ignore-titles"), diff --git a/crates/nu-command/src/commands/prepend.rs b/crates/nu-command/src/commands/prepend.rs index 7a383034b5..dead9e3040 100644 --- a/crates/nu-command/src/commands/prepend.rs +++ b/crates/nu-command/src/commands/prepend.rs @@ -41,7 +41,6 @@ impl WholeStreamCommand for Prepend { } fn prepend(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let row: Value = args.req(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/pwd.rs b/crates/nu-command/src/commands/pwd.rs index 02bec23066..a9965ec938 100644 --- a/crates/nu-command/src/commands/pwd.rs +++ b/crates/nu-command/src/commands/pwd.rs @@ -33,7 +33,6 @@ impl WholeStreamCommand for Pwd { pub fn pwd(args: CommandArgs) -> Result { let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; shell_manager.pwd(args) } diff --git a/crates/nu-command/src/commands/random/bool.rs b/crates/nu-command/src/commands/random/bool.rs index 0a9ada622e..a7c8c3ed5e 100644 --- a/crates/nu-command/src/commands/random/bool.rs +++ b/crates/nu-command/src/commands/random/bool.rs @@ -50,7 +50,6 @@ impl WholeStreamCommand for SubCommand { } pub fn bool_command(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let cmd_args = BoolArgs { bias: args.get_flag("bias")?, }; diff --git a/crates/nu-command/src/commands/random/chars.rs b/crates/nu-command/src/commands/random/chars.rs index 2d259c5742..734bf4390f 100644 --- a/crates/nu-command/src/commands/random/chars.rs +++ b/crates/nu-command/src/commands/random/chars.rs @@ -53,7 +53,6 @@ impl WholeStreamCommand for SubCommand { } pub fn chars(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let cmd_args = CharsArgs { length: args.get_flag("length")?, }; diff --git a/crates/nu-command/src/commands/random/decimal.rs b/crates/nu-command/src/commands/random/decimal.rs index eb5c262b43..a469b5f4c3 100644 --- a/crates/nu-command/src/commands/random/decimal.rs +++ b/crates/nu-command/src/commands/random/decimal.rs @@ -56,7 +56,6 @@ impl WholeStreamCommand for SubCommand { } pub fn decimal(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let cmd_args = DecimalArgs { range: args.opt(0)?, }; diff --git a/crates/nu-command/src/commands/random/dice.rs b/crates/nu-command/src/commands/random/dice.rs index 2c2ac6f17d..3e091f5078 100644 --- a/crates/nu-command/src/commands/random/dice.rs +++ b/crates/nu-command/src/commands/random/dice.rs @@ -60,7 +60,6 @@ impl WholeStreamCommand for SubCommand { pub fn dice(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let cmd_args = DiceArgs { dice: args.get_flag("dice")?, sides: args.get_flag("sides")?, diff --git a/crates/nu-command/src/commands/random/integer.rs b/crates/nu-command/src/commands/random/integer.rs index af1bd6ebc8..4e2905c698 100644 --- a/crates/nu-command/src/commands/random/integer.rs +++ b/crates/nu-command/src/commands/random/integer.rs @@ -56,7 +56,6 @@ impl WholeStreamCommand for SubCommand { } pub fn integer(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let cmd_args = IntegerArgs { range: args.opt(0)?, }; diff --git a/crates/nu-command/src/commands/range.rs b/crates/nu-command/src/commands/range.rs index 2f6d05422f..1a7b1a2fd5 100644 --- a/crates/nu-command/src/commands/range.rs +++ b/crates/nu-command/src/commands/range.rs @@ -55,7 +55,6 @@ impl WholeStreamCommand for Range { } fn range(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let cmd_args = RangeArgs { range: args.req(0)?, }; diff --git a/crates/nu-command/src/commands/reduce.rs b/crates/nu-command/src/commands/reduce.rs index 84386db9a3..a2fe3253c1 100644 --- a/crates/nu-command/src/commands/reduce.rs +++ b/crates/nu-command/src/commands/reduce.rs @@ -109,7 +109,6 @@ 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 args = args.evaluate_once()?; let reduce_args = ReduceArgs { block: args.req(0)?, fold: args.get_flag("fold")?, diff --git a/crates/nu-command/src/commands/reject.rs b/crates/nu-command/src/commands/reject.rs index ea2618ff70..1786e15f82 100644 --- a/crates/nu-command/src/commands/reject.rs +++ b/crates/nu-command/src/commands/reject.rs @@ -35,7 +35,6 @@ impl WholeStreamCommand for Reject { fn reject(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let fields: Vec> = args.rest(0)?; if fields.is_empty() { diff --git a/crates/nu-command/src/commands/rename.rs b/crates/nu-command/src/commands/rename.rs index b29e2e0e05..04640224d5 100644 --- a/crates/nu-command/src/commands/rename.rs +++ b/crates/nu-command/src/commands/rename.rs @@ -57,7 +57,6 @@ impl WholeStreamCommand for Rename { pub fn rename(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let column_name: Tagged = args.req(0)?; let rest: Vec> = args.rest(1)?; let input = args.input; diff --git a/crates/nu-command/src/commands/reverse.rs b/crates/nu-command/src/commands/reverse.rs index 8c3391eb02..579f332f4f 100644 --- a/crates/nu-command/src/commands/reverse.rs +++ b/crates/nu-command/src/commands/reverse.rs @@ -37,11 +37,9 @@ impl WholeStreamCommand for Reverse { } } +#[allow(clippy::needless_collect)] fn reverse(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let (input, _args) = args.parts(); - - let input = input.collect::>(); + let input = args.input.collect::>(); Ok((input.into_iter().rev().map(ReturnSuccess::value)).to_action_stream()) } diff --git a/crates/nu-command/src/commands/rm.rs b/crates/nu-command/src/commands/rm.rs index 762eaa5e56..35c3762ddf 100644 --- a/crates/nu-command/src/commands/rm.rs +++ b/crates/nu-command/src/commands/rm.rs @@ -65,7 +65,6 @@ impl WholeStreamCommand for Remove { fn rm(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); let shell_manager = args.shell_manager(); - let args = args.evaluate_once()?; let args = RemoveArgs { rest: args.rest(0)?, diff --git a/crates/nu-command/src/commands/roll/column.rs b/crates/nu-command/src/commands/roll/column.rs index 3fd37a91ab..9ff35d5c77 100644 --- a/crates/nu-command/src/commands/roll/column.rs +++ b/crates/nu-command/src/commands/roll/column.rs @@ -51,8 +51,6 @@ impl WholeStreamCommand for SubCommand { } pub fn roll(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; - let options = Arguments { by: args.opt(0)?, opposite: args.has_flag("opposite"), diff --git a/crates/nu-command/src/commands/roll/command.rs b/crates/nu-command/src/commands/roll/command.rs index 950608b236..bb414876ce 100644 --- a/crates/nu-command/src/commands/roll/command.rs +++ b/crates/nu-command/src/commands/roll/command.rs @@ -30,9 +30,8 @@ impl WholeStreamCommand for Command { } } -pub fn roll(args: CommandArgs) -> Result { +pub fn roll(mut args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let options = Arguments { by: args.opt(0)? }; diff --git a/crates/nu-command/src/commands/roll/up.rs b/crates/nu-command/src/commands/roll/up.rs index e5b8905365..5d24e76bf7 100644 --- a/crates/nu-command/src/commands/roll/up.rs +++ b/crates/nu-command/src/commands/roll/up.rs @@ -31,9 +31,8 @@ impl WholeStreamCommand for SubCommand { } } -pub fn roll(args: CommandArgs) -> Result { +pub fn roll(mut args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let options = Arguments { by: args.opt(0)? }; diff --git a/crates/nu-command/src/commands/rotate/command.rs b/crates/nu-command/src/commands/rotate/command.rs index 2d28a732d5..dbe448b7a0 100644 --- a/crates/nu-command/src/commands/rotate/command.rs +++ b/crates/nu-command/src/commands/rotate/command.rs @@ -33,7 +33,6 @@ impl WholeStreamCommand for Command { pub fn rotate(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let rest: Vec> = args.rest(0)?; let input = args.input.into_vec(); diff --git a/crates/nu-command/src/commands/rotate/counter_clockwise.rs b/crates/nu-command/src/commands/rotate/counter_clockwise.rs index 9d33e08c77..c8fbce95fd 100644 --- a/crates/nu-command/src/commands/rotate/counter_clockwise.rs +++ b/crates/nu-command/src/commands/rotate/counter_clockwise.rs @@ -33,7 +33,6 @@ impl WholeStreamCommand for SubCommand { pub fn rotate(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let rest: Vec> = args.rest(0)?; let input = args.input.into_vec(); diff --git a/crates/nu-command/src/commands/save.rs b/crates/nu-command/src/commands/save.rs index ae6839c96b..0212da6810 100644 --- a/crates/nu-command/src/commands/save.rs +++ b/crates/nu-command/src/commands/save.rs @@ -162,7 +162,6 @@ fn save(args: CommandArgs) -> Result { let scope = args.scope().clone(); 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"); diff --git a/crates/nu-command/src/commands/select.rs b/crates/nu-command/src/commands/select.rs index f34b889057..5c546f5160 100644 --- a/crates/nu-command/src/commands/select.rs +++ b/crates/nu-command/src/commands/select.rs @@ -47,7 +47,6 @@ impl WholeStreamCommand for Command { fn select(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let columns: Vec = args.rest(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/seq.rs b/crates/nu-command/src/commands/seq.rs index 51f251f736..6a1ac8a5d3 100644 --- a/crates/nu-command/src/commands/seq.rs +++ b/crates/nu-command/src/commands/seq.rs @@ -100,7 +100,6 @@ impl WholeStreamCommand for Seq { fn seq(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let rest_nums: Vec> = args.rest(0)?; let separator: Option> = args.get_flag("separator")?; let terminator: Option> = args.get_flag("terminator")?; diff --git a/crates/nu-command/src/commands/seq_dates.rs b/crates/nu-command/src/commands/seq_dates.rs index 6165cfcbae..199497d832 100644 --- a/crates/nu-command/src/commands/seq_dates.rs +++ b/crates/nu-command/src/commands/seq_dates.rs @@ -122,8 +122,6 @@ impl WholeStreamCommand for SeqDates { fn seq_dates(args: CommandArgs) -> Result { let _name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; - let separator: Option> = args.get_flag("separator")?; let output_format: Option> = args.get_flag("output-format")?; let input_format: Option> = args.get_flag("input-format")?; diff --git a/crates/nu-command/src/commands/skip/command.rs b/crates/nu-command/src/commands/skip/command.rs index a625f426f5..90f512477e 100644 --- a/crates/nu-command/src/commands/skip/command.rs +++ b/crates/nu-command/src/commands/skip/command.rs @@ -36,7 +36,6 @@ impl WholeStreamCommand for Command { } fn skip(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rows: Option> = args.opt(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/skip/until.rs b/crates/nu-command/src/commands/skip/until.rs index 9efdecc3cd..b50e776e1a 100644 --- a/crates/nu-command/src/commands/skip/until.rs +++ b/crates/nu-command/src/commands/skip/until.rs @@ -32,9 +32,8 @@ impl WholeStreamCommand for SubCommand { fn run_with_actions(&self, args: CommandArgs) -> Result { let ctx = Arc::new(EvaluationContext::from_args(&args)); let tag = args.call_info.name_tag.clone(); - let call_info = args.evaluate_once()?; - let block: CapturedBlock = call_info.req(0)?; + let block: CapturedBlock = args.req(0)?; let condition = { if block.block.block.len() != 1 { return Err(ShellError::labeled_error( @@ -64,7 +63,7 @@ impl WholeStreamCommand for SubCommand { } }; - Ok(call_info + Ok(args .input .skip_while(move |item| { let condition = condition.clone(); diff --git a/crates/nu-command/src/commands/skip/while_.rs b/crates/nu-command/src/commands/skip/while_.rs index 22f41b28d9..ff6248b6d9 100644 --- a/crates/nu-command/src/commands/skip/while_.rs +++ b/crates/nu-command/src/commands/skip/while_.rs @@ -32,9 +32,8 @@ impl WholeStreamCommand for SubCommand { fn run_with_actions(&self, args: CommandArgs) -> Result { let ctx = Arc::new(EvaluationContext::from_args(&args)); let tag = args.call_info.name_tag.clone(); - let call_info = args.evaluate_once()?; - let block: CapturedBlock = call_info.req(0)?; + let block: CapturedBlock = args.req(0)?; let condition = { if block.block.block.len() != 1 { return Err(ShellError::labeled_error( @@ -64,7 +63,7 @@ impl WholeStreamCommand for SubCommand { } }; - Ok(call_info + Ok(args .input .skip_while(move |item| { let item = item.clone(); diff --git a/crates/nu-command/src/commands/sleep.rs b/crates/nu-command/src/commands/sleep.rs index afa5256540..d98e984871 100644 --- a/crates/nu-command/src/commands/sleep.rs +++ b/crates/nu-command/src/commands/sleep.rs @@ -31,7 +31,6 @@ impl WholeStreamCommand for Sleep { fn run(&self, args: CommandArgs) -> Result { let ctrl_c = args.ctrl_c(); - let args = args.evaluate_once()?; let duration: Tagged = args.req(0)?; let rest: Vec> = args.rest(1)?; diff --git a/crates/nu-command/src/commands/sort_by.rs b/crates/nu-command/src/commands/sort_by.rs index cc7eb1b23f..7e20faa224 100644 --- a/crates/nu-command/src/commands/sort_by.rs +++ b/crates/nu-command/src/commands/sort_by.rs @@ -104,9 +104,8 @@ impl WholeStreamCommand for SortBy { } } -fn sort_by(args: CommandArgs) -> Result { +fn sort_by(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let mut args = args.evaluate_once()?; let rest: Vec> = args.rest(0)?; let insensitive = args.has_flag("insensitive"); diff --git a/crates/nu-command/src/commands/source.rs b/crates/nu-command/src/commands/source.rs index 2629f8e9d0..98d5baf02d 100644 --- a/crates/nu-command/src/commands/source.rs +++ b/crates/nu-command/src/commands/source.rs @@ -41,7 +41,6 @@ impl WholeStreamCommand for Source { pub fn source(args: CommandArgs) -> Result { let ctx = EvaluationContext::from_args(&args); - let args = args.evaluate_once()?; 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/split/column.rs b/crates/nu-command/src/commands/split/column.rs index f1d5bdbca8..0070f75a50 100644 --- a/crates/nu-command/src/commands/split/column.rs +++ b/crates/nu-command/src/commands/split/column.rs @@ -36,7 +36,6 @@ impl WholeStreamCommand for SubCommand { fn split_column(args: CommandArgs) -> Result { let name_span = args.call_info.name_tag.span; - let args = args.evaluate_once()?; let separator: Tagged = args.req(0)?; let rest: Vec> = args.rest(1)?; let collapse_empty = args.has_flag("collapse-empty"); diff --git a/crates/nu-command/src/commands/split/row.rs b/crates/nu-command/src/commands/split/row.rs index e5dbb287dd..2aa194b3d1 100644 --- a/crates/nu-command/src/commands/split/row.rs +++ b/crates/nu-command/src/commands/split/row.rs @@ -31,7 +31,6 @@ impl WholeStreamCommand for SubCommand { fn split_row(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let separator: Tagged = args.req(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/split_by.rs b/crates/nu-command/src/commands/split_by.rs index 782b7c87a7..069ef2ac83 100644 --- a/crates/nu-command/src/commands/split_by.rs +++ b/crates/nu-command/src/commands/split_by.rs @@ -32,7 +32,6 @@ impl WholeStreamCommand for SplitBy { pub fn split_by(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let column_name: Option> = args.opt(0)?; let values: Vec = args.input.collect(); diff --git a/crates/nu-command/src/commands/str_/capitalize.rs b/crates/nu-command/src/commands/str_/capitalize.rs index 77cc453a1f..ccafa6b938 100644 --- a/crates/nu-command/src/commands/str_/capitalize.rs +++ b/crates/nu-command/src/commands/str_/capitalize.rs @@ -44,11 +44,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/case/mod.rs b/crates/nu-command/src/commands/str_/case/mod.rs index 775bb0b406..660a775594 100644 --- a/crates/nu-command/src/commands/str_/case/mod.rs +++ b/crates/nu-command/src/commands/str_/case/mod.rs @@ -24,11 +24,12 @@ pub fn operate(args: CommandArgs, case_operation: &'static F) -> Result String + Send + Sync + 'static, { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/collect.rs b/crates/nu-command/src/commands/str_/collect.rs index 92f3dc6fa9..d1d7324656 100644 --- a/crates/nu-command/src/commands/str_/collect.rs +++ b/crates/nu-command/src/commands/str_/collect.rs @@ -49,11 +49,12 @@ impl WholeStreamCommand for SubCommand { pub fn collect(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let (options, input) = args.extract(|params| { - Ok(Arguments { - separator: params.opt(0)?, - }) - })?; + let (options, input) = ( + Arguments { + separator: args.opt(0)?, + }, + args.input, + ); let separator = options.separator(); diff --git a/crates/nu-command/src/commands/str_/contains.rs b/crates/nu-command/src/commands/str_/contains.rs index 1ca803c8b0..e0e4fc7780 100644 --- a/crates/nu-command/src/commands/str_/contains.rs +++ b/crates/nu-command/src/commands/str_/contains.rs @@ -56,13 +56,14 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - pattern: params.req(0)?, - insensitive: params.has_flag("insensitive"), - column_paths: params.rest(1)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + pattern: args.req(0)?, + insensitive: args.has_flag("insensitive"), + column_paths: args.rest(1)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/downcase.rs b/crates/nu-command/src/commands/str_/downcase.rs index 9f0d65dacf..6a1e719e9b 100644 --- a/crates/nu-command/src/commands/str_/downcase.rs +++ b/crates/nu-command/src/commands/str_/downcase.rs @@ -44,11 +44,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/ends_with.rs b/crates/nu-command/src/commands/str_/ends_with.rs index 0f03c4f0ce..704f1f9fab 100644 --- a/crates/nu-command/src/commands/str_/ends_with.rs +++ b/crates/nu-command/src/commands/str_/ends_with.rs @@ -47,12 +47,13 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - pattern: params.req(0)?, - column_paths: params.rest(1)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + pattern: args.req(0)?, + column_paths: args.rest(1)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/find_replace.rs b/crates/nu-command/src/commands/str_/find_replace.rs index f3951ce745..d6269858e9 100644 --- a/crates/nu-command/src/commands/str_/find_replace.rs +++ b/crates/nu-command/src/commands/str_/find_replace.rs @@ -61,14 +61,15 @@ impl WholeStreamCommand for SubCommand { struct FindReplace<'a>(&'a str, &'a str); fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - all: params.has_flag("all"), - find: params.req(0)?, - replace: params.req(1)?, - column_paths: params.rest(2)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + all: args.has_flag("all"), + find: args.req(0)?, + replace: args.req(1)?, + column_paths: args.rest(2)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/index_of.rs b/crates/nu-command/src/commands/str_/index_of.rs index 698cd8f5c7..218c4808a5 100644 --- a/crates/nu-command/src/commands/str_/index_of.rs +++ b/crates/nu-command/src/commands/str_/index_of.rs @@ -90,14 +90,15 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - pattern: params.req(0)?, - range: params.get_flag("range")?, - end: params.has_flag("end"), - column_paths: params.rest(1)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + pattern: args.req(0)?, + range: args.get_flag("range")?, + end: args.has_flag("end"), + column_paths: args.rest(1)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/length.rs b/crates/nu-command/src/commands/str_/length.rs index 4244255a57..d3a5f68bf9 100644 --- a/crates/nu-command/src/commands/str_/length.rs +++ b/crates/nu-command/src/commands/str_/length.rs @@ -52,11 +52,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/lpad.rs b/crates/nu-command/src/commands/str_/lpad.rs index 1eafe9be91..e3f1c86750 100644 --- a/crates/nu-command/src/commands/str_/lpad.rs +++ b/crates/nu-command/src/commands/str_/lpad.rs @@ -77,13 +77,14 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - length: params.req_named("length")?, - character: params.req_named("character")?, - column_paths: params.rest(0)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + length: args.req_named("length")?, + character: args.req_named("character")?, + column_paths: args.rest(0)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/reverse.rs b/crates/nu-command/src/commands/str_/reverse.rs index a743409bed..91bda709df 100644 --- a/crates/nu-command/src/commands/str_/reverse.rs +++ b/crates/nu-command/src/commands/str_/reverse.rs @@ -42,11 +42,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/rpad.rs b/crates/nu-command/src/commands/str_/rpad.rs index c9d51b06bb..bfacfaa1cd 100644 --- a/crates/nu-command/src/commands/str_/rpad.rs +++ b/crates/nu-command/src/commands/str_/rpad.rs @@ -77,13 +77,14 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - length: params.req_named("length")?, - character: params.req_named("character")?, - column_paths: params.rest(0)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + length: args.req_named("length")?, + character: args.req_named("character")?, + column_paths: args.rest(0)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/starts_with.rs b/crates/nu-command/src/commands/str_/starts_with.rs index 52aa727ff4..e64eb8f9a9 100644 --- a/crates/nu-command/src/commands/str_/starts_with.rs +++ b/crates/nu-command/src/commands/str_/starts_with.rs @@ -47,12 +47,13 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - pattern: params.req(0)?, - column_paths: params.rest(1)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + pattern: args.req(0)?, + column_paths: args.rest(1)?, + }), + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/substring.rs b/crates/nu-command/src/commands/str_/substring.rs index 071eaa16ff..972af5c52d 100644 --- a/crates/nu-command/src/commands/str_/substring.rs +++ b/crates/nu-command/src/commands/str_/substring.rs @@ -89,12 +89,13 @@ struct SubstringText(String, String); fn operate(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let (options, input) = args.extract(|params| { - Ok(Arguments { - range: params.req(0)?, - column_paths: params.rest(1)?, - }) - })?; + let (options, input) = ( + Arguments { + range: args.req(0)?, + column_paths: args.rest(1)?, + }, + args.input, + ); let indexes = Arc::new(process_arguments(&options, name)?.into()); diff --git a/crates/nu-command/src/commands/str_/to_datetime.rs b/crates/nu-command/src/commands/str_/to_datetime.rs index 6ce597b3db..3996e93ece 100644 --- a/crates/nu-command/src/commands/str_/to_datetime.rs +++ b/crates/nu-command/src/commands/str_/to_datetime.rs @@ -126,7 +126,6 @@ impl WholeStreamCommand for SubCommand { struct DatetimeFormat(String); fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let options = Arguments { timezone: args.get_flag("timezone")?, offset: args.get_flag("offset")?, diff --git a/crates/nu-command/src/commands/str_/to_decimal.rs b/crates/nu-command/src/commands/str_/to_decimal.rs index e9523fecf4..5703b70119 100644 --- a/crates/nu-command/src/commands/str_/to_decimal.rs +++ b/crates/nu-command/src/commands/str_/to_decimal.rs @@ -47,11 +47,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/str_/to_integer.rs b/crates/nu-command/src/commands/str_/to_integer.rs index 3bb96751a5..92bca01ab9 100644 --- a/crates/nu-command/src/commands/str_/to_integer.rs +++ b/crates/nu-command/src/commands/str_/to_integer.rs @@ -64,7 +64,6 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let options = Arguments { radix: args.get_flag("radix")?, column_paths: args.rest(0)?, diff --git a/crates/nu-command/src/commands/str_/trim/mod.rs b/crates/nu-command/src/commands/str_/trim/mod.rs index b9b18333a7..a4b8a57244 100644 --- a/crates/nu-command/src/commands/str_/trim/mod.rs +++ b/crates/nu-command/src/commands/str_/trim/mod.rs @@ -23,12 +23,13 @@ pub fn operate(args: CommandArgs, trim_operation: &'static F) -> Result) -> String + Send + Sync + 'static, { - let (options, input) = args.extract(|params| { - Ok(Arc::new(Arguments { - character: params.get_flag("char")?, - column_paths: params.rest(0)?, - })) - })?; + let (options, input) = ( + Arc::new(Arguments { + character: args.get_flag("char")?, + column_paths: args.rest(0)?, + }), + args.input, + ); let to_trim = options.character.as_ref().map(|tagged| tagged.item); diff --git a/crates/nu-command/src/commands/str_/upcase.rs b/crates/nu-command/src/commands/str_/upcase.rs index 9f513235aa..d09af76023 100644 --- a/crates/nu-command/src/commands/str_/upcase.rs +++ b/crates/nu-command/src/commands/str_/upcase.rs @@ -44,11 +44,12 @@ impl WholeStreamCommand for SubCommand { } fn operate(args: CommandArgs) -> Result { - let (options, input) = args.extract(|params| { - Ok(Arguments { - column_paths: params.rest(0)?, - }) - })?; + let (options, input) = ( + Arguments { + column_paths: args.rest(0)?, + }, + args.input, + ); Ok(input .map(move |v| { diff --git a/crates/nu-command/src/commands/table/command.rs b/crates/nu-command/src/commands/table/command.rs index 13ed0101d3..1441a7e3e5 100644 --- a/crates/nu-command/src/commands/table/command.rs +++ b/crates/nu-command/src/commands/table/command.rs @@ -165,8 +165,7 @@ fn values_to_entries( entries } -fn table(args: CommandArgs) -> Result { - let mut args = args.evaluate_once()?; +fn table(mut args: CommandArgs) -> Result { let configuration = args.configs().lock().global_config(); // Ideally, get_color_config would get all the colors configured in the config.toml diff --git a/crates/nu-command/src/commands/termsize.rs b/crates/nu-command/src/commands/termsize.rs index 29e5a86232..bed3eb47f2 100644 --- a/crates/nu-command/src/commands/termsize.rs +++ b/crates/nu-command/src/commands/termsize.rs @@ -29,7 +29,6 @@ impl WholeStreamCommand for TermSize { fn run_with_actions(&self, args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let wide = args.has_flag("wide"); let tall = args.has_flag("tall"); diff --git a/crates/nu-command/src/commands/to_csv.rs b/crates/nu-command/src/commands/to_csv.rs index ad20a0a200..9b95a0c09f 100644 --- a/crates/nu-command/src/commands/to_csv.rs +++ b/crates/nu-command/src/commands/to_csv.rs @@ -37,7 +37,6 @@ impl WholeStreamCommand for ToCsv { fn to_csv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let separator: Option = args.get_flag("separator")?; let noheaders = args.has_flag("noheaders"); let input = args.input; diff --git a/crates/nu-command/src/commands/to_html.rs b/crates/nu-command/src/commands/to_html.rs index 0bc0f5fe72..85e419ce10 100644 --- a/crates/nu-command/src/commands/to_html.rs +++ b/crates/nu-command/src/commands/to_html.rs @@ -259,7 +259,6 @@ fn get_list_of_theme_names() -> Vec { fn to_html(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let html_color = args.has_flag("html_color"); let no_color = args.has_flag("no_color"); let dark = args.has_flag("dark"); diff --git a/crates/nu-command/src/commands/to_json.rs b/crates/nu-command/src/commands/to_json.rs index d879c047cf..fcfae971dd 100644 --- a/crates/nu-command/src/commands/to_json.rs +++ b/crates/nu-command/src/commands/to_json.rs @@ -154,7 +154,6 @@ fn json_list(input: &[Value]) -> Result, ShellError> { fn to_json(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let pretty: Option = args.get_flag("pretty")?; let name_span = name_tag.span; diff --git a/crates/nu-command/src/commands/to_md.rs b/crates/nu-command/src/commands/to_md.rs index 36828d46de..ab34e3fb15 100644 --- a/crates/nu-command/src/commands/to_md.rs +++ b/crates/nu-command/src/commands/to_md.rs @@ -84,7 +84,6 @@ impl WholeStreamCommand for Command { fn to_md(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let arguments = Arguments { per_element: args.has_flag("per-element"), pretty: args.has_flag("pretty"), diff --git a/crates/nu-command/src/commands/to_toml.rs b/crates/nu-command/src/commands/to_toml.rs index a5c8a920d6..ac12382a33 100644 --- a/crates/nu-command/src/commands/to_toml.rs +++ b/crates/nu-command/src/commands/to_toml.rs @@ -129,7 +129,6 @@ fn collect_values(input: &[Value]) -> Result, ShellError> { } fn to_toml(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let name_tag = args.name_tag(); let name_span = name_tag.span; let input: Vec = args.input.collect(); diff --git a/crates/nu-command/src/commands/to_tsv.rs b/crates/nu-command/src/commands/to_tsv.rs index 6a025a428d..61b4436116 100644 --- a/crates/nu-command/src/commands/to_tsv.rs +++ b/crates/nu-command/src/commands/to_tsv.rs @@ -30,7 +30,6 @@ impl WholeStreamCommand for ToTsv { fn to_tsv(args: CommandArgs) -> Result { let name = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let noheaders = args.has_flag("noheaders"); to_delimited_data(noheaders, '\t', "TSV", args.input, name) diff --git a/crates/nu-command/src/commands/to_url.rs b/crates/nu-command/src/commands/to_url.rs index 432df3464e..2044295393 100644 --- a/crates/nu-command/src/commands/to_url.rs +++ b/crates/nu-command/src/commands/to_url.rs @@ -24,7 +24,6 @@ impl WholeStreamCommand for ToUrl { } fn to_url(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let tag = args.name_tag(); let input = args.input; diff --git a/crates/nu-command/src/commands/to_xml.rs b/crates/nu-command/src/commands/to_xml.rs index b8db63e0d4..1757c59b99 100644 --- a/crates/nu-command/src/commands/to_xml.rs +++ b/crates/nu-command/src/commands/to_xml.rs @@ -129,7 +129,6 @@ pub fn write_xml_events( fn to_xml(args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); let name_span = name_tag.span; - let args = args.evaluate_once()?; let pretty: Option = args.get_flag("pretty")?; let input: Vec = args.input.collect(); diff --git a/crates/nu-command/src/commands/to_yaml.rs b/crates/nu-command/src/commands/to_yaml.rs index a23ea1e4b5..37e6679b8e 100644 --- a/crates/nu-command/src/commands/to_yaml.rs +++ b/crates/nu-command/src/commands/to_yaml.rs @@ -116,7 +116,6 @@ pub fn value_to_yaml_value(v: &Value) -> Result { } fn to_yaml(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let name_tag = args.name_tag(); let name_span = name_tag.span; diff --git a/crates/nu-command/src/commands/touch.rs b/crates/nu-command/src/commands/touch.rs index d84a4cc9de..61becb0034 100644 --- a/crates/nu-command/src/commands/touch.rs +++ b/crates/nu-command/src/commands/touch.rs @@ -45,7 +45,6 @@ impl WholeStreamCommand for Touch { } fn touch(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let target: Tagged = args.req(0)?; let rest: Vec> = args.rest(1)?; diff --git a/crates/nu-command/src/commands/uniq.rs b/crates/nu-command/src/commands/uniq.rs index b038bd819b..2b8379b000 100644 --- a/crates/nu-command/src/commands/uniq.rs +++ b/crates/nu-command/src/commands/uniq.rs @@ -92,7 +92,6 @@ fn to_lowercase(value: nu_protocol::Value) -> nu_protocol::Value { } fn uniq(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let should_show_count = args.has_flag("count"); let show_repeated = args.has_flag("repeated"); let ignore_case = args.has_flag("ignore-case"); diff --git a/crates/nu-command/src/commands/update.rs b/crates/nu-command/src/commands/update.rs index 9a82a28929..ef20ec19d6 100644 --- a/crates/nu-command/src/commands/update.rs +++ b/crates/nu-command/src/commands/update.rs @@ -175,7 +175,6 @@ 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 args = args.evaluate_once()?; let field: ColumnPath = args.req(0)?; let replacement: Value = args.req(1)?; diff --git a/crates/nu-command/src/commands/url_/host.rs b/crates/nu-command/src/commands/url_/host.rs index 064c61c5d9..2b93487329 100644 --- a/crates/nu-command/src/commands/url_/host.rs +++ b/crates/nu-command/src/commands/url_/host.rs @@ -23,7 +23,6 @@ impl WholeStreamCommand for UrlHost { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/url_/path.rs b/crates/nu-command/src/commands/url_/path.rs index 70c02f1ad9..8a5c4b03bf 100644 --- a/crates/nu-command/src/commands/url_/path.rs +++ b/crates/nu-command/src/commands/url_/path.rs @@ -23,7 +23,6 @@ impl WholeStreamCommand for UrlPath { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let input = args.input; diff --git a/crates/nu-command/src/commands/url_/query.rs b/crates/nu-command/src/commands/url_/query.rs index 1675889e6d..23cb4527e8 100644 --- a/crates/nu-command/src/commands/url_/query.rs +++ b/crates/nu-command/src/commands/url_/query.rs @@ -23,7 +23,6 @@ impl WholeStreamCommand for UrlQuery { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let input = args.input; Ok(operate(input, rest, &query)) diff --git a/crates/nu-command/src/commands/url_/scheme.rs b/crates/nu-command/src/commands/url_/scheme.rs index 2889019470..62422f7553 100644 --- a/crates/nu-command/src/commands/url_/scheme.rs +++ b/crates/nu-command/src/commands/url_/scheme.rs @@ -22,7 +22,6 @@ impl WholeStreamCommand for UrlScheme { } fn run_with_actions(&self, args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; Ok(operate(args.input, rest, &Url::scheme)) } diff --git a/crates/nu-command/src/commands/where_.rs b/crates/nu-command/src/commands/where_.rs index edd4a56388..d855a5bca7 100644 --- a/crates/nu-command/src/commands/where_.rs +++ b/crates/nu-command/src/commands/where_.rs @@ -59,7 +59,6 @@ impl WholeStreamCommand for Command { fn where_command(args: CommandArgs) -> Result { let context = Arc::new(EvaluationContext::from_args(&args)); let tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let block: CapturedBlock = args.req(0)?; diff --git a/crates/nu-command/src/commands/which_.rs b/crates/nu-command/src/commands/which_.rs index fe0ee45a40..25cecb0bd6 100644 --- a/crates/nu-command/src/commands/which_.rs +++ b/crates/nu-command/src/commands/which_.rs @@ -210,8 +210,6 @@ fn which_single(application: Tagged, all: bool, scope: &Scope) -> Vec Result { - let args = args.evaluate_once()?; - let which_args = WhichArgs { applications: args.rest_with_minimum(0, 1)?, all: args.has_flag("all"), diff --git a/crates/nu-command/src/commands/with_env.rs b/crates/nu-command/src/commands/with_env.rs index 401bdb0a9b..acafc3d247 100644 --- a/crates/nu-command/src/commands/with_env.rs +++ b/crates/nu-command/src/commands/with_env.rs @@ -70,7 +70,6 @@ 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 args = args.evaluate_once()?; let variable: Value = args.req(0)?; let block: CapturedBlock = args.req(1)?; diff --git a/crates/nu-command/src/commands/wrap.rs b/crates/nu-command/src/commands/wrap.rs index 5f1264542e..d334a9b16e 100644 --- a/crates/nu-command/src/commands/wrap.rs +++ b/crates/nu-command/src/commands/wrap.rs @@ -73,7 +73,6 @@ impl WholeStreamCommand for Wrap { } fn wrap(args: CommandArgs) -> Result { - let args = args.evaluate_once()?; let column: Option> = args.opt(0)?; let mut result_table = vec![]; diff --git a/crates/nu-command/src/examples/double_echo.rs b/crates/nu-command/src/examples/double_echo.rs index ca032592cd..1898b41ace 100644 --- a/crates/nu-command/src/examples/double_echo.rs +++ b/crates/nu-command/src/examples/double_echo.rs @@ -28,7 +28,6 @@ impl WholeStreamCommand for Command { fn run_with_actions(&self, args: CommandArgs) -> Result { let name_tag = args.call_info.name_tag.clone(); - let args = args.evaluate_once()?; let rest: Vec = args.rest(0)?; let mut base_value = UntaggedValue::string("Yehuda Katz in Ecuador").into_value(name_tag); diff --git a/crates/nu-data/src/lib.rs b/crates/nu-data/src/lib.rs index f37ce7bfaf..60614f1589 100644 --- a/crates/nu-data/src/lib.rs +++ b/crates/nu-data/src/lib.rs @@ -3,7 +3,6 @@ pub mod config; pub mod dict; pub mod keybinding; pub mod primitive; -pub mod types; pub mod utils; pub mod value; diff --git a/crates/nu-data/src/types.rs b/crates/nu-data/src/types.rs deleted file mode 100644 index cd91e0c86f..0000000000 --- a/crates/nu-data/src/types.rs +++ /dev/null @@ -1,94 +0,0 @@ -use log::trace; -use nu_errors::{CoerceInto, ShellError}; -use nu_protocol::{Primitive, SpannedTypeName, UntaggedValue, Value}; -use nu_source::{Tagged, TaggedItem}; - -pub trait ExtractType: Sized { - fn extract(value: &Value) -> Result; -} - -impl ExtractType for Tagged { - fn extract(value: &Value) -> Result, ShellError> { - let name = std::any::type_name::(); - trace!(" Extracting {:?} for Tagged<{}>", value, name); - - Ok(T::extract(value)?.tagged(value.tag())) - } -} - -impl ExtractType for bool { - fn extract(value: &Value) -> Result { - trace!("Extracting {:?} for bool", value); - - match &value { - Value { - value: UntaggedValue::Primitive(Primitive::Boolean(b)), - .. - } => Ok(*b), - other => Err(ShellError::type_error("Boolean", other.spanned_type_name())), - } - } -} - -impl ExtractType for std::path::PathBuf { - fn extract(value: &Value) -> Result { - trace!("Extracting {:?} for PathBuf", value); - - match &value { - Value { - value: UntaggedValue::Primitive(Primitive::FilePath(p)), - .. - } => Ok(p.clone()), - other => Err(ShellError::type_error("Path", other.spanned_type_name())), - } - } -} - -impl ExtractType for i64 { - fn extract(value: &Value) -> Result { - trace!("Extracting {:?} for i64", value); - - match &value { - &Value { - value: UntaggedValue::Primitive(Primitive::Int(int)), - .. - } => Ok(*int), - &Value { - value: UntaggedValue::Primitive(Primitive::BigInt(int)), - .. - } => Ok(int.tagged(&value.tag).coerce_into("converting to i64")?), - other => Err(ShellError::type_error("Integer", other.spanned_type_name())), - } - } -} - -impl ExtractType for u64 { - fn extract(value: &Value) -> Result { - trace!("Extracting {:?} for u64", value); - - match &value { - &Value { - value: UntaggedValue::Primitive(Primitive::BigInt(int)), - .. - } => Ok(int.tagged(&value.tag).coerce_into("converting to u64")?), - other => Err(ShellError::type_error( - "Big Integer", - other.spanned_type_name(), - )), - } - } -} - -impl ExtractType for String { - fn extract(value: &Value) -> Result { - trace!("Extracting {:?} for String", value); - - match value { - Value { - value: UntaggedValue::Primitive(Primitive::String(string)), - .. - } => Ok(string.clone()), - other => Err(ShellError::type_error("String", other.spanned_type_name())), - } - } -} diff --git a/crates/nu-engine/src/command_args.rs b/crates/nu-engine/src/command_args.rs index 6f34ee37cc..6e730337de 100644 --- a/crates/nu-engine/src/command_args.rs +++ b/crates/nu-engine/src/command_args.rs @@ -1,18 +1,15 @@ -use crate::env::host::Host; use crate::evaluate::scope::Scope; use crate::evaluation_context::EvaluationContext; use crate::shell::shell_manager::ShellManager; use crate::FromValue; use crate::{call_info::UnevaluatedCallInfo, config_holder::ConfigHolder}; -use derive_new::new; +use crate::{env::host::Host, evaluate_baseline_expr}; use getset::Getters; use nu_errors::ShellError; -use nu_protocol::EvaluatedArgs; -use nu_protocol::{CallInfo, Value}; +use nu_protocol::hir::SpannedExpression; use nu_source::Tag; use nu_stream::InputStream; use parking_lot::Mutex; -use std::ops::Deref; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -48,131 +45,19 @@ impl CommandArgs { pub fn shell_manager(&self) -> ShellManager { self.context.shell_manager.clone() } -} -pub type RunnableContext = CommandArgs; - -impl std::fmt::Debug for CommandArgs { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.call_info.fmt(f) - } -} - -impl CommandArgs { - pub fn evaluate_once(self) -> Result { - let ctx = self.context.clone(); - - let input = self.input; - let call_info = self.call_info.evaluate(&ctx)?; - - Ok(EvaluatedCommandArgs::new(ctx, call_info, input)) - } - - pub fn extract( - self, - f: impl FnOnce(&EvaluatedCommandArgsWithoutInput) -> Result, - ) -> Result<(T, InputStream), ShellError> { - let evaluated_args = self.evaluate_once()?; - - Ok((f(&evaluated_args.args)?, evaluated_args.input)) - } -} - -pub struct EvaluatedCommandArgs { - pub args: EvaluatedCommandArgsWithoutInput, - pub input: InputStream, -} - -impl Deref for EvaluatedCommandArgs { - type Target = EvaluatedCommandArgsWithoutInput; - fn deref(&self) -> &Self::Target { - &self.args - } -} - -impl EvaluatedCommandArgs { - pub fn new( - context: EvaluationContext, - call_info: CallInfo, - input: impl Into, - ) -> EvaluatedCommandArgs { - EvaluatedCommandArgs { - args: EvaluatedCommandArgsWithoutInput { context, call_info }, - input: input.into(), - } - } - - pub fn name_tag(&self) -> Tag { - self.args.call_info.name_tag.clone() - } - - pub fn parts(self) -> (InputStream, EvaluatedArgs) { - let EvaluatedCommandArgs { args, input } = self; - - (input, args.call_info.args) - } - - pub fn split(self) -> (InputStream, EvaluatedCommandArgsWithoutInput) { - let EvaluatedCommandArgs { args, input } = self; - - (input, args) - } -} - -#[derive(Getters, new)] -#[get = "pub(crate)"] -pub struct EvaluatedCommandArgsWithoutInput { - pub context: EvaluationContext, - pub call_info: CallInfo, -} - -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 - .args - .nth(pos) - .ok_or_else(|| ShellError::unimplemented("Better error: expect_nth")) - } - - pub fn get_flag(&self, name: &str) -> Result, ShellError> { - if let Some(arg) = self.call_info.args.get(name) { - FromValue::from_value(arg).map(Some) + pub fn nth(&self, pos: usize) -> Option<&SpannedExpression> { + if let Some(positional) = &self.call_info.args.positional { + positional.get(pos) } else { - Ok(None) + None } } - pub fn req_named(&self, name: &str) -> Result { - self.call_info - .args - .expect_get(name) - .and_then(|x| FromValue::from_value(x)) - } - - pub fn has_flag(&self, name: &str) -> bool { - self.call_info.args.has(name) - } - pub fn req(&self, pos: usize) -> Result { - if let Some(v) = self.nth(pos) { - FromValue::from_value(v) + if let Some(expr) = self.nth(pos) { + let result = evaluate_baseline_expr(expr, &self.context)?; + FromValue::from_value(&result) } else { Err(ShellError::labeled_error( "Position beyond end of command arguments", @@ -182,9 +67,34 @@ impl EvaluatedCommandArgsWithoutInput { } } + pub fn req_named(&self, name: &str) -> Result { + match self.get_flag(name)? { + Some(v) => Ok(v), + None => Err(ShellError::labeled_error( + "Missing flag", + format!("expected {} flag", name), + &self.call_info.name_tag, + )), + } + } + + pub fn has_flag(&self, name: &str) -> bool { + self.call_info.args.switch_preset(name) + } + + pub fn get_flag(&self, name: &str) -> Result, ShellError> { + if let Some(expr) = self.call_info.args.get_flag(name) { + let result = evaluate_baseline_expr(expr, &self.context)?; + FromValue::from_value(&result).map(Some) + } else { + Ok(None) + } + } + pub fn opt(&self, pos: usize) -> Result, ShellError> { - if let Some(v) = self.nth(pos) { - FromValue::from_value(v).map(Some) + if let Some(expr) = self.nth(pos) { + let result = evaluate_baseline_expr(expr, &self.context)?; + FromValue::from_value(&result).map(Some) } else { Ok(None) } @@ -193,8 +103,11 @@ impl EvaluatedCommandArgsWithoutInput { pub fn rest(&self, starting_pos: usize) -> Result, ShellError> { let mut output = vec![]; - for val in self.call_info.args.positional_iter().skip(starting_pos) { - output.push(FromValue::from_value(val)?); + if let Some(positional) = &self.call_info.args.positional { + for expr in positional.iter().skip(starting_pos) { + let result = evaluate_baseline_expr(expr, &self.context)?; + output.push(FromValue::from_value(&result)?); + } } Ok(output) @@ -213,4 +126,16 @@ impl EvaluatedCommandArgsWithoutInput { Ok(output) } + + pub fn name_tag(&self) -> Tag { + self.call_info.name_tag.clone() + } +} + +pub type RunnableContext = CommandArgs; + +impl std::fmt::Debug for CommandArgs { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.call_info.fmt(f) + } } diff --git a/crates/nu-engine/src/filesystem/filesystem_shell.rs b/crates/nu-engine/src/filesystem/filesystem_shell.rs index c8c8e15438..705e1da5a4 100644 --- a/crates/nu-engine/src/filesystem/filesystem_shell.rs +++ b/crates/nu-engine/src/filesystem/filesystem_shell.rs @@ -1,10 +1,13 @@ -use crate::filesystem::dir_info::{DirBuilder, DirInfo}; use crate::filesystem::path::canonicalize; 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::EvaluatedCommandArgs, BufCodecReader}; +use crate::BufCodecReader; +use crate::{ + filesystem::dir_info::{DirBuilder, DirInfo}, + CommandArgs, +}; use encoding_rs::Encoding; use nu_data::config::LocalConfigDiff; use nu_protocol::{CommandAction, ConfigPath, TaggedDictBuilder, Value}; @@ -776,7 +779,7 @@ impl Shell for FilesystemShell { self.path.clone() } - fn pwd(&self, args: EvaluatedCommandArgs) -> Result { + fn pwd(&self, args: CommandArgs) -> 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 8eda272a98..d06d10aa8b 100644 --- a/crates/nu-engine/src/lib.rs +++ b/crates/nu-engine/src/lib.rs @@ -16,9 +16,7 @@ pub mod shell; mod whole_stream_command; pub use crate::call_info::UnevaluatedCallInfo; -pub use crate::command_args::{ - CommandArgs, EvaluatedCommandArgs, EvaluatedCommandArgsWithoutInput, RunnableContext, -}; +pub use crate::command_args::{CommandArgs, RunnableContext}; pub use crate::config_holder::ConfigHolder; pub use crate::documentation::{generate_docs, get_brief_help, get_documentation, get_full_help}; pub use crate::env::host::FakeHost; diff --git a/crates/nu-engine/src/plugin/run_plugin.rs b/crates/nu-engine/src/plugin/run_plugin.rs index bb80c113c3..c3e5896127 100644 --- a/crates/nu-engine/src/plugin/run_plugin.rs +++ b/crates/nu-engine/src/plugin/run_plugin.rs @@ -1,12 +1,17 @@ -use crate::command_args::CommandArgs; -use crate::whole_stream_command::{whole_stream_command, WholeStreamCommand}; +use crate::{command_args::CommandArgs, evaluate_baseline_expr, UnevaluatedCallInfo}; +use crate::{ + whole_stream_command::{whole_stream_command, WholeStreamCommand}, + EvaluationContext, +}; use derive_new::new; +use indexmap::IndexMap; use log::trace; use nu_errors::ShellError; use nu_plugin::jsonrpc::JsonRpc; -use nu_protocol::{Primitive, ReturnValue, Signature, UntaggedValue, Value}; -use nu_stream::{ActionStream, ToActionStream}; +use nu_protocol::{hir, Primitive, ReturnValue, Signature, UntaggedValue, Value}; +use nu_source::Tag; +use nu_stream::{ActionStream, InputStream, ToActionStream}; use serde::{self, Deserialize, Serialize}; use std::collections::VecDeque; use std::io::prelude::*; @@ -119,7 +124,7 @@ fn run_filter(path: String, args: CommandArgs) -> Result Result Result { - let args = args.evaluate_once()?; - let call_info = args.call_info.clone(); + let (call_info, input) = evaluate_once(args)?; - let input: Vec = args.input.into_vec(); + let input: Vec = input.into_vec(); let request = JsonRpc::new("sink", (call_info, input)); let request_raw = serde_json::to_string(&request); @@ -446,3 +448,80 @@ fn run_sink(path: String, args: CommandArgs) -> Result )) } } + +/// Associated information for the call of a command, including the args passed to the command and a tag that spans the name of the command being called +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct CallInfo { + /// The arguments associated with this call + pub args: EvaluatedArgs, + /// The tag (underline-able position) of the name of the call itself + pub name_tag: Tag, +} + +/// The set of positional and named arguments, after their values have been evaluated. +/// +/// * Positional arguments are those who are given as values, without any associated flag. For example, in `foo arg1 arg2`, both `arg1` and `arg2` are positional arguments. +/// * Named arguments are those associated with a flag. For example, `foo --given bar` the named argument would be name `given` and the value `bar`. +#[derive(Debug, Default, new, Serialize, Deserialize, Clone)] +pub struct EvaluatedArgs { + pub positional: Option>, + pub named: Option>, +} + +fn evaluate_once(args: CommandArgs) -> Result<(CallInfo, InputStream), ShellError> { + let input = args.input; + let call_info = evaluate_command(args.call_info, args.context)?; + + Ok((call_info, input)) +} + +fn evaluate_command( + args: UnevaluatedCallInfo, + ctx: EvaluationContext, +) -> Result { + let name_tag = args.name_tag.clone(); + let args = evaluate_args(&args.args, &ctx)?; + + Ok(CallInfo { args, name_tag }) +} + +fn evaluate_args(call: &hir::Call, ctx: &EvaluationContext) -> Result { + let mut positional_args: Vec = vec![]; + + if let Some(positional) = &call.positional { + for pos in positional { + let result = evaluate_baseline_expr(pos, ctx)?; + positional_args.push(result); + } + } + + let positional = if !positional_args.is_empty() { + Some(positional_args) + } else { + None + }; + + let mut named_args = IndexMap::new(); + + if let Some(named) = &call.named { + for (name, value) in named.iter() { + match value { + hir::NamedValue::PresentSwitch(tag) => { + named_args.insert(name.clone(), UntaggedValue::boolean(true).into_value(tag)); + } + hir::NamedValue::Value(_, expr) => { + named_args.insert(name.clone(), evaluate_baseline_expr(expr, ctx)?); + } + _ => {} + }; + } + } + + let named = if !named_args.is_empty() { + Some(named_args) + } else { + None + }; + + Ok(EvaluatedArgs::new(positional, named)) +} diff --git a/crates/nu-engine/src/shell/mod.rs b/crates/nu-engine/src/shell/mod.rs index f4ca3c66e9..d19189cfcd 100644 --- a/crates/nu-engine/src/shell/mod.rs +++ b/crates/nu-engine/src/shell/mod.rs @@ -1,8 +1,8 @@ use nu_stream::{ActionStream, OutputStream}; -use crate::command_args::EvaluatedCommandArgs; use crate::maybe_text_codec::StringOrBinary; pub use crate::shell::shell_args::{CdArgs, CopyArgs, LsArgs, MkdirArgs, MvArgs, RemoveArgs}; +use crate::CommandArgs; use encoding_rs::Encoding; use nu_errors::ShellError; use nu_source::{Span, Tag}; @@ -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: EvaluatedCommandArgs) -> Result; + fn pwd(&self, args: CommandArgs) -> 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 13725a2693..7511f194a2 100644 --- a/crates/nu-engine/src/shell/shell_manager.rs +++ b/crates/nu-engine/src/shell/shell_manager.rs @@ -1,6 +1,6 @@ use crate::shell::Shell; -use crate::{command_args::EvaluatedCommandArgs, FilesystemShell}; use crate::{filesystem::filesystem_shell::FilesystemShellMode, maybe_text_codec::StringOrBinary}; +use crate::{CommandArgs, FilesystemShell}; use nu_stream::{ActionStream, OutputStream}; use crate::shell::shell_args::{CdArgs, CopyArgs, LsArgs, MkdirArgs, MvArgs, RemoveArgs}; @@ -78,7 +78,7 @@ impl ShellManager { self.shells.lock()[self.current_shell()].path() } - pub fn pwd(&self, args: EvaluatedCommandArgs) -> Result { + pub fn pwd(&self, args: CommandArgs) -> 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 1946ee1a6a..81e95fec0b 100644 --- a/crates/nu-engine/src/shell/value_shell.rs +++ b/crates/nu-engine/src/shell/value_shell.rs @@ -1,7 +1,7 @@ -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; +use crate::CommandArgs; use encoding_rs::Encoding; use nu_errors::ShellError; use nu_protocol::ValueStructure; @@ -217,7 +217,7 @@ impl Shell for ValueShell { self.path.clone() } - fn pwd(&self, args: EvaluatedCommandArgs) -> Result { + fn pwd(&self, args: CommandArgs) -> Result { Ok(ActionStream::one( UntaggedValue::string(self.path()).into_value(&args.call_info.name_tag), )) diff --git a/crates/nu-protocol/src/dataframe/nu_dataframe.rs b/crates/nu-protocol/src/dataframe/nu_dataframe.rs index 6a6b22dd65..12e2974cfa 100644 --- a/crates/nu-protocol/src/dataframe/nu_dataframe.rs +++ b/crates/nu-protocol/src/dataframe/nu_dataframe.rs @@ -97,11 +97,13 @@ impl NuDataFrame { UntaggedValue::DataFrame(PolarsData::EagerDataFrame(df)) => Some(df), _ => None, }) - .ok_or(ShellError::labeled_error( - "No dataframe in stream", - "no dataframe found in input stream", - span, - )) + .ok_or_else(|| { + ShellError::labeled_error( + "No dataframe in stream", + "no dataframe found in input stream", + span, + ) + }) } pub fn try_from_iter(iter: T, tag: &Tag) -> Result diff --git a/crates/nu-protocol/src/dataframe/nu_groupby.rs b/crates/nu-protocol/src/dataframe/nu_groupby.rs index 8ec8df9ab5..7357385317 100644 --- a/crates/nu-protocol/src/dataframe/nu_groupby.rs +++ b/crates/nu-protocol/src/dataframe/nu_groupby.rs @@ -33,11 +33,13 @@ impl NuGroupBy { UntaggedValue::DataFrame(PolarsData::GroupBy(group)) => Some(group), _ => None, }) - .ok_or(ShellError::labeled_error( - "No groupby object in stream", - "no groupby object found in input stream", - span, - )) + .ok_or_else(|| { + ShellError::labeled_error( + "No groupby object in stream", + "no groupby object found in input stream", + span, + ) + }) } pub fn to_groupby(&self) -> Result { diff --git a/crates/nu-protocol/src/dataframe/nu_series.rs b/crates/nu-protocol/src/dataframe/nu_series.rs index c5e50ab5cc..a301071139 100644 --- a/crates/nu-protocol/src/dataframe/nu_series.rs +++ b/crates/nu-protocol/src/dataframe/nu_series.rs @@ -60,11 +60,13 @@ impl NuSeries { UntaggedValue::DataFrame(PolarsData::Series(series)) => Some(series), _ => None, }) - .ok_or(ShellError::labeled_error( - "No series in stream", - "no series found in input stream", - span, - )) + .ok_or_else(|| { + ShellError::labeled_error( + "No series in stream", + "no series found in input stream", + span, + ) + }) } pub fn try_from_iter(iter: T, name: Option) -> Result @@ -265,7 +267,8 @@ fn insert_value(value: Value, vec_values: &mut Vec) -> Result<(), ShellEr // Checking that the type for the value is the same // for the previous value in the column if vec_values.is_empty() { - Ok(vec_values.push(value)) + vec_values.push(value); + Ok(()) } else { let prev_value = &vec_values[vec_values.len() - 1]; @@ -281,7 +284,10 @@ fn insert_value(value: Value, vec_values: &mut Vec) -> Result<(), ShellEr | ( UntaggedValue::Primitive(Primitive::String(_)), UntaggedValue::Primitive(Primitive::String(_)), - ) => Ok(vec_values.push(value)), + ) => { + vec_values.push(value); + Ok(()) + } _ => Err(ShellError::labeled_error_with_secondary( "Different values in column", "Value with different type", diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 1e3cc061e9..697c6c6042 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -1287,6 +1287,12 @@ impl NamedValue { vec![] } } + pub fn get_contents(&self) -> Option<&SpannedExpression> { + match self { + NamedValue::Value(_, expr) => Some(expr), + _ => None, + } + } } impl PrettyDebugWithSource for NamedValue { @@ -1341,6 +1347,13 @@ impl Call { .unwrap_or(false) } + pub fn get_flag(&self, switch: &str) -> Option<&SpannedExpression> { + self.named + .as_ref() + .and_then(|n| n.get(switch)) + .and_then(|x| x.get_contents()) + } + pub fn set_initial_flags(&mut self, signature: &crate::Signature) { for (named, value) in signature.named.iter() { if self.named.is_none() {