mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Make arg eval lazy, remove old arg evaluation code (#3603)
* Remove old argument eval * Merge main * fmt * clippy * clippy * clippy
This commit is contained in:
parent
c4163c3621
commit
8ac572ed27
218 changed files with 448 additions and 1075 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#[macro_use]
|
||||
pub(crate) mod macros;
|
||||
|
||||
mod from_delimited_data;
|
||||
mod to_delimited_data;
|
||||
|
||||
|
|
|
@ -54,7 +54,6 @@ impl WholeStreamCommand for Command {
|
|||
fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
|||
}
|
||||
};
|
||||
|
||||
let scope = args.scope();
|
||||
let scope = args.scope().clone();
|
||||
|
||||
let init = Ok(InputStream::one(
|
||||
UntaggedValue::boolean(true).into_value(&tag),
|
||||
|
|
|
@ -113,8 +113,6 @@ Format: #
|
|||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let code: Option<Tagged<String>> = args.opt(0)?;
|
||||
let escape: Option<Tagged<String>> = args.get_flag("escape")?;
|
||||
let osc: Option<Tagged<String>> = 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,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let fgstart: Option<Value> = args.get_flag("fgstart")?;
|
||||
let fgend: Option<Value> = args.get_flag("fgend")?;
|
||||
let bgstart: Option<Value> = args.get_flag("bgstart")?;
|
||||
|
|
|
@ -38,8 +38,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let column_paths: Vec<_> = args.rest(0)?;
|
||||
|
||||
let result: Vec<Value> = args
|
||||
|
|
|
@ -54,7 +54,6 @@ impl WholeStreamCommand for Command {
|
|||
fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
|||
}
|
||||
};
|
||||
|
||||
let scope = args.scope();
|
||||
let scope = args.scope().clone();
|
||||
|
||||
let init = Ok(InputStream::one(
|
||||
UntaggedValue::boolean(false).into_value(&tag),
|
||||
|
|
|
@ -22,8 +22,7 @@ impl WholeStreamCommand for Command {
|
|||
"Append a row to the table."
|
||||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let mut args = args.evaluate_once()?;
|
||||
fn run(&self, mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let mut value: Value = args.req(0)?;
|
||||
|
||||
let mut prepend = vec![];
|
||||
|
|
|
@ -74,7 +74,6 @@ fn benchmark(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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")?,
|
||||
|
|
|
@ -23,7 +23,6 @@ impl WholeStreamCommand for BuildString {
|
|||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<Value> = args.rest(0)?;
|
||||
|
||||
let mut output_string = String::new();
|
||||
|
|
|
@ -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<ActionStream, ShellError> {
|
||||
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<ActionStream, ShellError> {
|
|||
let mut selected_year: i32 = current_year;
|
||||
let mut current_day_option: Option<u32> = 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<u64> = 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<Value>,
|
||||
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<Value>,
|
||||
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<Tagged<u64>> = 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::<Tagged<String>>("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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ impl WholeStreamCommand for Cd {
|
|||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
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)
|
||||
|
|
|
@ -168,7 +168,6 @@ impl WholeStreamCommand for Char {
|
|||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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)?,
|
||||
|
|
|
@ -38,11 +38,12 @@ impl WholeStreamCommand for Compact {
|
|||
}
|
||||
|
||||
pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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| {
|
||||
|
|
|
@ -38,7 +38,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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)?;
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
let args = args.evaluate_once()?;
|
||||
let remove: Tagged<String> = args.req(0)?;
|
||||
|
||||
let key = remove.to_string();
|
||||
|
|
|
@ -53,7 +53,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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)?;
|
||||
|
|
|
@ -39,7 +39,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let set_into: Tagged<String> = args.req(0)?;
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ impl WholeStreamCommand for Cpy {
|
|||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
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)?,
|
||||
|
|
|
@ -121,9 +121,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let quantile: Option<Tagged<f64>> = args.get_flag("quantile")?;
|
||||
let operation: Tagged<String> = args.req(0)?;
|
||||
|
@ -139,11 +138,9 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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)) => {
|
||||
|
|
|
@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let column: Tagged<String> = args.req(0)?;
|
||||
|
||||
let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
||||
|
|
|
@ -37,16 +37,15 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let columns: Vec<Value> = 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)
|
||||
|
|
|
@ -39,9 +39,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<Vec<Value>> = args.opt(0)?;
|
||||
|
|
|
@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<Vec<Value>> = args.opt(0)?;
|
||||
|
|
|
@ -31,9 +31,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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
|
||||
|
|
|
@ -33,9 +33,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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| {
|
||||
|
|
|
@ -36,9 +36,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let columns: Vec<Value> = args.req(0)?;
|
||||
|
||||
let (col_string, col_span) = convert_columns(&columns, &tag)?;
|
||||
|
|
|
@ -40,9 +40,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<Value> = args.req(0)?;
|
||||
|
|
|
@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
|
||||
let rows = match rows {
|
||||
|
|
|
@ -65,9 +65,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<Value> = args.req(1)?;
|
||||
|
|
|
@ -19,8 +19,6 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let values = args
|
||||
.context
|
||||
.scope
|
||||
|
|
|
@ -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<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
let file: Tagged<PathBuf> = args.req(0)?;
|
||||
|
||||
let df = match file.item().extension() {
|
||||
|
@ -108,7 +107,7 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
};
|
||||
|
||||
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<OutputStream, ShellError> {
|
|||
)))
|
||||
}
|
||||
|
||||
fn from_parquet(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
fn from_parquet(args: CommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
let file: Tagged<PathBuf> = args.req(0)?;
|
||||
|
||||
let r = File::open(&file.item)
|
||||
|
@ -130,7 +129,7 @@ fn from_parquet(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame
|
|||
.map_err(|e| parse_polars_error::<&str>(&e, &file.tag.span, None))
|
||||
}
|
||||
|
||||
fn from_json(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
fn from_json(args: CommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
let file: Tagged<PathBuf> = args.req(0)?;
|
||||
|
||||
let r = File::open(&file.item)
|
||||
|
@ -143,7 +142,7 @@ fn from_json(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame, S
|
|||
.map_err(|e| parse_polars_error::<&str>(&e, &file.tag.span, None))
|
||||
}
|
||||
|
||||
fn from_csv(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
fn from_csv(args: CommandArgs) -> Result<polars::prelude::DataFrame, ShellError> {
|
||||
let file: Tagged<PathBuf> = args.req(0)?;
|
||||
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
||||
let no_header: bool = args.has_flag("no_header");
|
||||
|
@ -164,7 +163,7 @@ fn from_csv(args: EvaluatedCommandArgs) -> Result<polars::prelude::DataFrame, Sh
|
|||
&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!(),
|
||||
};
|
||||
|
|
|
@ -39,9 +39,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let id_col: Vec<Value> = args.req(0)?;
|
||||
let val_col: Vec<Value> = args.req(1)?;
|
||||
|
@ -67,7 +66,7 @@ fn check_column_datatypes<T: AsRef<str>>(
|
|||
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",
|
||||
|
|
|
@ -78,9 +78,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
// Extracting the pivot col from arguments
|
||||
let pivot_col: Tagged<String> = args.req(0)?;
|
||||
|
|
|
@ -53,9 +53,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
||||
let fraction: Option<Tagged<f64>> = args.get_flag("fraction")?;
|
||||
|
|
|
@ -37,9 +37,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let columns: Vec<Value> = args.req(0)?;
|
||||
|
||||
|
|
|
@ -47,9 +47,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
||||
let tail: bool = args.has_flag("tail");
|
||||
|
|
|
@ -34,9 +34,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
|
||||
let offset: Tagged<usize> = args.req(0)?;
|
||||
let size: Tagged<usize> = args.req(1)?;
|
||||
|
|
|
@ -38,9 +38,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let columns: Vec<Value> = args.req(0)?;
|
||||
let reverse = args.has_flag("reverse");
|
||||
|
||||
|
|
|
@ -36,9 +36,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
|
||||
let rows = match rows {
|
||||
|
|
|
@ -57,9 +57,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let file_name: Tagged<PathBuf> = args.req(0)?;
|
||||
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
||||
let no_header: bool = args.has_flag("no_header");
|
||||
|
@ -92,7 +91,7 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
&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!(),
|
||||
};
|
||||
|
|
|
@ -20,7 +20,6 @@ impl WholeStreamCommand for DataFrame {
|
|||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let df = NuDataFrame::try_from_iter(args.input, &tag)?;
|
||||
|
||||
|
|
|
@ -44,9 +44,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let file_name: Tagged<PathBuf> = args.req(0)?;
|
||||
|
||||
let mut df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
||||
|
|
|
@ -25,7 +25,6 @@ impl WholeStreamCommand for DataFrame {
|
|||
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let name: Option<Tagged<String>> = args.opt(0)?;
|
||||
let name = name.map(|v| v.item);
|
||||
|
|
|
@ -5,13 +5,12 @@ use polars::prelude::PolarsError;
|
|||
|
||||
// Converts a Vec<Value> to a Vec<String> 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<String>, 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,
|
||||
|
|
|
@ -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<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
|||
_ => 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<OutputStream, ShellError> {
|
|||
)),
|
||||
}?;
|
||||
|
||||
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,
|
||||
)))
|
||||
}
|
||||
|
|
|
@ -40,9 +40,8 @@ impl WholeStreamCommand for DataFrame {
|
|||
}
|
||||
}
|
||||
|
||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let mut args = args.evaluate_once()?;
|
||||
let value: Value = args.req(0)?;
|
||||
let name: Tagged<String> = args.req(2)?;
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ impl WholeStreamCommand for Date {
|
|||
|
||||
pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let format: Tagged<String> = args.req(0)?;
|
||||
let table: Option<bool> = args.get_flag("table")?;
|
||||
|
|
|
@ -41,8 +41,7 @@ impl WholeStreamCommand for Date {
|
|||
}
|
||||
|
||||
fn list_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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();
|
||||
|
|
|
@ -31,8 +31,6 @@ pub fn date_now(tag: &Tag) -> Value {
|
|||
}
|
||||
|
||||
pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let value = date_now(&args.call_info.name_tag);
|
||||
|
||||
Ok(OutputStream::one(value))
|
||||
|
|
|
@ -34,7 +34,6 @@ impl WholeStreamCommand for Date {
|
|||
}
|
||||
|
||||
fn to_table(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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))
|
||||
|
|
|
@ -55,7 +55,6 @@ impl WholeStreamCommand for Date {
|
|||
|
||||
fn to_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let timezone: Tagged<String> = args.req(0)?;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ impl WholeStreamCommand for Debug {
|
|||
}
|
||||
|
||||
fn debug_value(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let raw = args.has_flag("raw");
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ impl WholeStreamCommand for Default {
|
|||
}
|
||||
|
||||
fn default(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let column: Tagged<String> = args.req(0)?;
|
||||
let value: Value = args.req(1)?;
|
||||
|
||||
|
|
|
@ -59,11 +59,10 @@ impl WholeStreamCommand for Do {
|
|||
}
|
||||
}
|
||||
|
||||
fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
||||
fn do_(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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"),
|
||||
|
|
|
@ -43,7 +43,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let columns: Option<Tagged<u64>> = args.opt(0)?;
|
||||
|
||||
let to_drop = if let Some(quantity) = columns {
|
||||
|
|
|
@ -47,7 +47,6 @@ impl WholeStreamCommand for Command {
|
|||
}
|
||||
|
||||
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<u64>> = args.opt(0)?;
|
||||
let v: Vec<_> = args.input.into_vec();
|
||||
|
||||
|
|
|
@ -88,8 +88,6 @@ fn du(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||
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"),
|
||||
|
|
|
@ -114,10 +114,9 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
|
|||
dict.into_value()
|
||||
}
|
||||
|
||||
fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
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");
|
||||
|
|
|
@ -37,10 +37,9 @@ impl WholeStreamCommand for EachGroup {
|
|||
}]
|
||||
}
|
||||
|
||||
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
let context = Arc::new(args.context.clone());
|
||||
let external_redirection = args.call_info.args.external_redirection;
|
||||
|
||||
let group_size: Tagged<usize> = args.req(0)?;
|
||||
let block: CapturedBlock = args.req(1)?;
|
||||
|
|
|
@ -41,11 +41,10 @@ impl WholeStreamCommand for EachWindow {
|
|||
}]
|
||||
}
|
||||
|
||||
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
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<usize> = args.req(0)?;
|
||||
let block: CapturedBlock = args.req(1)?;
|
||||
let stride: Option<Tagged<usize>> = args.get_flag("stride")?;
|
||||
|
|
|
@ -54,7 +54,6 @@ pub fn expand_value_to_stream(v: Value) -> InputStream {
|
|||
}
|
||||
|
||||
fn echo(args: CommandArgs) -> Result<InputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let rest: Vec<Value> = args.rest(0)?;
|
||||
|
||||
let stream = rest.into_iter().map(|i| match i.as_string() {
|
||||
|
|
|
@ -84,7 +84,6 @@ fn is_empty(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||
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<CapturedBlock> = args.get_flag("block")?;
|
||||
let columns: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
||||
|
|
|
@ -74,7 +74,6 @@ fn enter(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||
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<PathBuf> = args.req(0)?;
|
||||
let encoding: Option<Tagged<String>> = args.get_flag("encoding")?;
|
||||
|
|
|
@ -56,8 +56,6 @@ impl WholeStreamCommand for Every {
|
|||
}
|
||||
|
||||
fn every(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let stride: u64 = args.req(0)?;
|
||||
let skip: bool = args.has_flag("skip");
|
||||
let input = args.input;
|
||||
|
|
|
@ -64,7 +64,6 @@ fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
use std::process::Command;
|
||||
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let args = ExecArgs {
|
||||
command: args.req(0)?,
|
||||
|
|
|
@ -44,15 +44,13 @@ impl WholeStreamCommand for Exit {
|
|||
}
|
||||
|
||||
pub fn exit(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
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::<i64>(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)
|
||||
|
|
|
@ -47,7 +47,6 @@ impl WholeStreamCommand for First {
|
|||
}
|
||||
|
||||
fn first(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ impl WholeStreamCommand for Command {
|
|||
|
||||
fn flatten(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
let columns: Vec<Tagged<String>> = args.rest(0)?;
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -111,8 +111,7 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
|
|||
fn for_in(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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
|
||||
|
|
|
@ -40,7 +40,6 @@ impl WholeStreamCommand for Format {
|
|||
|
||||
fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||
let args = args.evaluate_once()?;
|
||||
let pattern: Tagged<String> = args.req(0)?;
|
||||
|
||||
let format_pattern = format(&pattern);
|
||||
|
|
|
@ -83,9 +83,7 @@ fn process_row(
|
|||
}
|
||||
}
|
||||
|
||||
fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = raw_args.evaluate_once()?;
|
||||
|
||||
fn filesize(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let field: ColumnPath = args.req(0)?;
|
||||
let format: Tagged<String> = args.req(1)?;
|
||||
let field = Arc::new(field);
|
||||
|
|
|
@ -62,7 +62,6 @@ impl WholeStreamCommand for FromCsv {
|
|||
|
||||
fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let noheaders = args.has_flag("noheaders");
|
||||
let separator: Option<Value> = args.get_flag("separator")?;
|
||||
|
|
|
@ -68,7 +68,6 @@ fn headerfieldvalue_to_value(tag: &Tag, value: &HeaderFieldValue) -> UntaggedVal
|
|||
|
||||
fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let preview_body: Option<Tagged<usize>> = args.get_flag("preview-body")?;
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ impl WholeStreamCommand for FromIcs {
|
|||
}
|
||||
|
||||
fn from_ics(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ pub fn from_ini_string_to_value(
|
|||
}
|
||||
|
||||
fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
let concat_string = input.collect_string(tag.clone())?;
|
||||
|
|
|
@ -65,7 +65,6 @@ pub fn from_json_string_to_value(s: String, tag: impl Into<Tag>) -> nu_json::Res
|
|||
fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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())?;
|
||||
|
|
|
@ -52,14 +52,10 @@ fn from_ods(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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::<Vec<Value>>("sheets")? {
|
||||
sel_sheets = convert_columns(columns.as_slice())?;
|
||||
}
|
||||
|
||||
let bytes = args.input.collect_binary(tag.clone())?;
|
||||
|
|
|
@ -237,7 +237,6 @@ fn from_ssv_string_to_value(
|
|||
|
||||
fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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");
|
||||
|
|
|
@ -61,7 +61,6 @@ pub fn from_toml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value
|
|||
}
|
||||
|
||||
pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ impl WholeStreamCommand for FromTsv {
|
|||
|
||||
fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
let noheaders = args.has_flag("noheaders");
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ impl WholeStreamCommand for FromUrl {
|
|||
}
|
||||
|
||||
fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ impl WholeStreamCommand for FromVcf {
|
|||
}
|
||||
|
||||
fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -58,14 +58,10 @@ fn from_xlsx(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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::<Vec<Value>>("sheets")? {
|
||||
sel_sheets = convert_columns(columns.as_slice())?;
|
||||
}
|
||||
|
||||
let value = args.input.collect_binary(tag.clone())?;
|
||||
|
|
|
@ -95,7 +95,6 @@ pub fn from_xml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value,
|
|||
}
|
||||
|
||||
fn from_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -132,7 +132,6 @@ pub fn from_yaml_string_to_value(s: String, tag: impl Into<Tag>) -> Result<Value
|
|||
}
|
||||
|
||||
fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let tag = args.name_tag();
|
||||
let input = args.input;
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ impl WholeStreamCommand for Command {
|
|||
}
|
||||
|
||||
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
let mut input = args.input;
|
||||
|
||||
|
|
|
@ -126,7 +126,6 @@ enum Grouper {
|
|||
pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<Value> = args.input.collect();
|
||||
|
|
|
@ -54,7 +54,6 @@ enum GroupByColumn {
|
|||
|
||||
pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let args = args.evaluate_once()?;
|
||||
let column_name: Option<Tagged<String>> = args.opt(0)?;
|
||||
let format: Option<Tagged<String>> = args.get_flag("format")?;
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
|
||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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");
|
||||
|
|
|
@ -50,7 +50,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
||||
Ok(args
|
||||
|
|
|
@ -34,7 +34,6 @@ impl WholeStreamCommand for Help {
|
|||
fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let scope = args.scope().clone();
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
||||
|
||||
|
|
|
@ -59,21 +59,10 @@ impl WholeStreamCommand for Histogram {
|
|||
|
||||
pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let (input, args) = args.evaluate_once()?.parts();
|
||||
|
||||
let values: Vec<Value> = input.collect();
|
||||
|
||||
let mut columns = args
|
||||
.positional_iter()
|
||||
.map(|c| c.as_column_path())
|
||||
.filter_map(Result::ok)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let evaluate_with = if let Some(path) = args.get("use") {
|
||||
Some(evaluator(path.as_column_path()?.item))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut columns = args.rest::<ColumnPath>(0)?;
|
||||
let evaluate_with = args.get_flag::<ColumnPath>("use")?.map(evaluator);
|
||||
let values: Vec<Value> = args.input.collect();
|
||||
|
||||
let column_grouper = if !columns.is_empty() {
|
||||
columns
|
||||
|
|
|
@ -28,7 +28,6 @@ impl WholeStreamCommand for History {
|
|||
fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
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");
|
||||
|
||||
|
|
|
@ -57,12 +57,11 @@ impl WholeStreamCommand for If {
|
|||
]
|
||||
}
|
||||
}
|
||||
fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
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)?;
|
||||
|
|
|
@ -154,7 +154,6 @@ fn process_row(
|
|||
|
||||
fn insert(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
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;
|
||||
|
|
|
@ -113,7 +113,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn into_binary(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let skip: Option<Value> = args.get_flag("skip")?;
|
||||
let bytes: Option<Value> = args.get_flag("bytes")?;
|
||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
|
|
@ -79,7 +79,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
||||
Ok(args
|
||||
|
|
|
@ -81,8 +81,6 @@ impl WholeStreamCommand for SubCommand {
|
|||
}
|
||||
|
||||
fn into_string(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
|
||||
let decimals: Option<Tagged<u64>> = args.get_flag("decimals")?;
|
||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ impl WholeStreamCommand for Command {
|
|||
}
|
||||
|
||||
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once()?;
|
||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue