mirror of
https://github.com/nushell/nushell.git
synced 2025-05-11 13:34:26 +02: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
@ -603,7 +603,7 @@ mod serde_json_tests {
|
|||||||
Color::Fixed(255),
|
Color::Fixed(255),
|
||||||
];
|
];
|
||||||
|
|
||||||
for color in colors.into_iter() {
|
for color in colors.iter() {
|
||||||
let serialized = serde_json::to_string(&color).unwrap();
|
let serialized = serde_json::to_string(&color).unwrap();
|
||||||
let deserialized: Color = serde_json::from_str(&serialized).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 from_delimited_data;
|
||||||
mod to_delimited_data;
|
mod to_delimited_data;
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ impl WholeStreamCommand for Command {
|
|||||||
fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn all(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let all_args = AllArgs {
|
let all_args = AllArgs {
|
||||||
predicate: args.req(0)?,
|
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(
|
let init = Ok(InputStream::one(
|
||||||
UntaggedValue::boolean(true).into_value(&tag),
|
UntaggedValue::boolean(true).into_value(&tag),
|
||||||
|
@ -113,8 +113,6 @@ Format: #
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let code: Option<Tagged<String>> = args.opt(0)?;
|
let code: Option<Tagged<String>> = args.opt(0)?;
|
||||||
let escape: Option<Tagged<String>> = args.get_flag("escape")?;
|
let escape: Option<Tagged<String>> = args.get_flag("escape")?;
|
||||||
let osc: Option<Tagged<String>> = args.get_flag("osc")?;
|
let osc: Option<Tagged<String>> = args.get_flag("osc")?;
|
||||||
@ -170,7 +168,7 @@ Format: #
|
|||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"Expected ansi code",
|
"Expected ansi code",
|
||||||
"expect 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> {
|
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let fgstart: Option<Value> = args.get_flag("fgstart")?;
|
let fgstart: Option<Value> = args.get_flag("fgstart")?;
|
||||||
let fgend: Option<Value> = args.get_flag("fgend")?;
|
let fgend: Option<Value> = args.get_flag("fgend")?;
|
||||||
let bgstart: Option<Value> = args.get_flag("bgstart")?;
|
let bgstart: Option<Value> = args.get_flag("bgstart")?;
|
||||||
|
@ -38,8 +38,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let column_paths: Vec<_> = args.rest(0)?;
|
let column_paths: Vec<_> = args.rest(0)?;
|
||||||
|
|
||||||
let result: Vec<Value> = args
|
let result: Vec<Value> = args
|
||||||
|
@ -54,7 +54,6 @@ impl WholeStreamCommand for Command {
|
|||||||
fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn any(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let any_args = AnyArgs {
|
let any_args = AnyArgs {
|
||||||
predicate: args.req(0)?,
|
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(
|
let init = Ok(InputStream::one(
|
||||||
UntaggedValue::boolean(false).into_value(&tag),
|
UntaggedValue::boolean(false).into_value(&tag),
|
||||||
|
@ -22,8 +22,7 @@ impl WholeStreamCommand for Command {
|
|||||||
"Append a row to the table."
|
"Append a row to the table."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let mut value: Value = args.req(0)?;
|
let mut value: Value = args.req(0)?;
|
||||||
|
|
||||||
let mut prepend = vec![];
|
let mut prepend = vec![];
|
||||||
|
@ -74,7 +74,6 @@ fn benchmark(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
let mut context = EvaluationContext::from_args(&args);
|
let mut context = EvaluationContext::from_args(&args);
|
||||||
let scope = args.scope().clone();
|
let scope = args.scope().clone();
|
||||||
|
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let cmd_args = BenchmarkArgs {
|
let cmd_args = BenchmarkArgs {
|
||||||
block: args.req(0)?,
|
block: args.req(0)?,
|
||||||
passthrough: args.get_flag("passthrough")?,
|
passthrough: args.get_flag("passthrough")?,
|
||||||
|
@ -23,7 +23,6 @@ impl WholeStreamCommand for BuildString {
|
|||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let rest: Vec<Value> = args.rest(0)?;
|
let rest: Vec<Value> = args.rest(0)?;
|
||||||
|
|
||||||
let mut output_string = String::new();
|
let mut output_string = String::new();
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use chrono::{Datelike, Local, NaiveDate};
|
use chrono::{Datelike, Local, NaiveDate};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand};
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{Dictionary, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
use nu_source::Tagged;
|
||||||
|
|
||||||
pub struct Cal;
|
pub struct Cal;
|
||||||
|
|
||||||
@ -66,7 +67,6 @@ impl WholeStreamCommand for Cal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn cal(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
pub fn cal(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let mut calendar_vec_deque = VecDeque::new();
|
let mut calendar_vec_deque = VecDeque::new();
|
||||||
let tag = args.call_info.name_tag.clone();
|
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 selected_year: i32 = current_year;
|
||||||
let mut current_day_option: Option<u32> = Some(current_day);
|
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") {
|
let full_year_value: Option<u64> = args.get_flag("full-year")?;
|
||||||
if let Ok(year_u64) = full_year_value.as_u64() {
|
let month_range = if let Some(full_year_value) = full_year_value {
|
||||||
selected_year = year_u64 as i32;
|
selected_year = full_year_value as i32;
|
||||||
|
|
||||||
if selected_year != current_year {
|
if selected_year != current_year {
|
||||||
current_day_option = None
|
current_day_option = None
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(get_invalid_year_shell_error(&full_year_value.tag()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(1, 12)
|
(1, 12)
|
||||||
@ -165,7 +162,7 @@ fn get_current_date() -> (i32, u32, u32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_months_of_year_to_table(
|
fn add_months_of_year_to_table(
|
||||||
args: &EvaluatedCommandArgs,
|
args: &CommandArgs,
|
||||||
mut calendar_vec_deque: &mut VecDeque<Value>,
|
mut calendar_vec_deque: &mut VecDeque<Value>,
|
||||||
tag: &Tag,
|
tag: &Tag,
|
||||||
selected_year: i32,
|
selected_year: i32,
|
||||||
@ -198,7 +195,7 @@ fn add_months_of_year_to_table(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn add_month_to_table(
|
fn add_month_to_table(
|
||||||
args: &EvaluatedCommandArgs,
|
args: &CommandArgs,
|
||||||
calendar_vec_deque: &mut VecDeque<Value>,
|
calendar_vec_deque: &mut VecDeque<Value>,
|
||||||
tag: &Tag,
|
tag: &Tag,
|
||||||
selected_year: i32,
|
selected_year: i32,
|
||||||
@ -207,9 +204,11 @@ fn add_month_to_table(
|
|||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
let month_helper_result = MonthHelper::new(selected_year, current_month);
|
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 {
|
let month_helper = match month_helper_result {
|
||||||
Ok(month_helper) => month_helper,
|
Ok(month_helper) => month_helper,
|
||||||
Err(()) => match args.call_info.args.get("full-year") {
|
Err(()) => match full_year_value {
|
||||||
Some(full_year_value) => {
|
Some(full_year_value) => {
|
||||||
return Err(get_invalid_year_shell_error(&full_year_value.tag()))
|
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();
|
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 Some(day) = args.get_flag::<Tagged<String>>("week-start")? {
|
||||||
if let Ok(day) = week_start_value.as_string() {
|
if days_of_the_week.contains(&day.item.as_str()) {
|
||||||
if days_of_the_week.contains(&day.as_str()) {
|
week_start_day = day.item;
|
||||||
week_start_day = day;
|
} else {
|
||||||
} else {
|
return Err(ShellError::labeled_error(
|
||||||
return Err(ShellError::labeled_error(
|
"The specified week start day is invalid",
|
||||||
"The specified week start day is invalid",
|
"invalid week start day",
|
||||||
"invalid week start day",
|
day.tag(),
|
||||||
week_start_value.tag(),
|
));
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ impl WholeStreamCommand for Cd {
|
|||||||
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let shell_manager = args.shell_manager();
|
let shell_manager = args.shell_manager();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let args = CdArgs { path: args.opt(0)? };
|
let args = CdArgs { path: args.opt(0)? };
|
||||||
|
|
||||||
shell_manager.cd(args, name)
|
shell_manager.cd(args, name)
|
||||||
|
@ -168,7 +168,6 @@ impl WholeStreamCommand for Char {
|
|||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args_tag = args.call_info.name_tag.clone();
|
let args_tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let args = CharArgs {
|
let args = CharArgs {
|
||||||
name: args.opt(0)?,
|
name: args.opt(0)?,
|
||||||
rest: args.rest(1)?,
|
rest: args.rest(1)?,
|
||||||
|
@ -38,11 +38,12 @@ impl WholeStreamCommand for Compact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn compact(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let (args, input) = args.extract(|params| {
|
let (args, input) = (
|
||||||
Ok(CompactArgs {
|
CompactArgs {
|
||||||
columns: params.rest(0)?,
|
columns: args.rest(0)?,
|
||||||
})
|
},
|
||||||
})?;
|
args.input,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(input
|
Ok(input
|
||||||
.filter(move |item| {
|
.filter(move |item| {
|
||||||
|
@ -38,7 +38,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn get(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let column_path = args.req(0)?;
|
let column_path = args.req(0)?;
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn remove(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let remove: Tagged<String> = args.req(0)?;
|
let remove: Tagged<String> = args.req(0)?;
|
||||||
|
|
||||||
let key = remove.to_string();
|
let key = remove.to_string();
|
||||||
|
@ -53,7 +53,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let column_path = args.req(0)?;
|
let column_path = args.req(0)?;
|
||||||
let mut value: Value = args.req(1)?;
|
let mut value: Value = args.req(1)?;
|
||||||
|
@ -39,7 +39,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn set_into(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let set_into: Tagged<String> = args.req(0)?;
|
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> {
|
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let shell_manager = args.shell_manager();
|
let shell_manager = args.shell_manager();
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let args = CopyArgs {
|
let args = CopyArgs {
|
||||||
src: args.req(0)?,
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let quantile: Option<Tagged<f64>> = args.get_flag("quantile")?;
|
let quantile: Option<Tagged<f64>> = args.get_flag("quantile")?;
|
||||||
let operation: Tagged<String> = args.req(0)?;
|
let operation: Tagged<String> = args.req(0)?;
|
||||||
@ -139,11 +138,9 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
None => (None, Span::unknown()),
|
None => (None, Span::unknown()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let value = args.input.next().ok_or(ShellError::labeled_error(
|
let value = args.input.next().ok_or_else(|| {
|
||||||
"Empty stream",
|
ShellError::labeled_error("Empty stream", "No value found in the stream", &tag)
|
||||||
"No value found in the stream",
|
})?;
|
||||||
&tag,
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let res = match value.value {
|
let res = match value.value {
|
||||||
UntaggedValue::DataFrame(PolarsData::GroupBy(nu_groupby)) => {
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let column: Tagged<String> = args.req(0)?;
|
let column: Tagged<String> = args.req(0)?;
|
||||||
|
|
||||||
let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let columns: Vec<Value> = args.req(0)?;
|
let columns: Vec<Value> = args.req(0)?;
|
||||||
let (col_string, col_span) = convert_columns(&columns, &tag)?;
|
let (col_string, col_span) = convert_columns(&columns, &tag)?;
|
||||||
|
|
||||||
let df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
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
|
Some(col) => df
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.drop(col)
|
.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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
// Extracting the selection columns of the columns to perform the aggregation
|
// Extracting the selection columns of the columns to perform the aggregation
|
||||||
let columns: Option<Vec<Value>> = args.opt(0)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
// Extracting the selection columns of the columns to perform the aggregation
|
// Extracting the selection columns of the columns to perform the aggregation
|
||||||
let columns: Option<Vec<Value>> = args.opt(0)?;
|
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 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 df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
||||||
let col_names = df
|
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 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 df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
||||||
let res = df.as_ref().to_dummies().map_err(|e| {
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let columns: Vec<Value> = args.req(0)?;
|
let columns: Vec<Value> = args.req(0)?;
|
||||||
|
|
||||||
let (col_string, col_span) = convert_columns(&columns, &tag)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
// Extracting the names of the columns to perform the groupby
|
// Extracting the names of the columns to perform the groupby
|
||||||
let by_columns: Vec<Value> = args.req(0)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||||
|
|
||||||
let rows = match rows {
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let r_df: Value = args.req(0)?;
|
let r_df: Value = args.req(0)?;
|
||||||
let l_col: Vec<Value> = args.req(1)?;
|
let l_col: Vec<Value> = args.req(1)?;
|
||||||
|
@ -19,8 +19,6 @@ impl WholeStreamCommand for DataFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let values = args
|
let values = args
|
||||||
.context
|
.context
|
||||||
.scope
|
.scope
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::{commands::dataframe::utils::parse_polars_error, prelude::*};
|
use crate::{commands::dataframe::utils::parse_polars_error, prelude::*};
|
||||||
use nu_engine::{EvaluatedCommandArgs, WholeStreamCommand};
|
use nu_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
dataframe::NuDataFrame, Primitive, Signature, SyntaxShape, UntaggedValue, Value,
|
dataframe::NuDataFrame, Primitive, Signature, SyntaxShape, UntaggedValue, Value,
|
||||||
@ -75,7 +75,6 @@ impl WholeStreamCommand for DataFrame {
|
|||||||
|
|
||||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let file: Tagged<PathBuf> = args.req(0)?;
|
let file: Tagged<PathBuf> = args.req(0)?;
|
||||||
|
|
||||||
let df = match file.item().extension() {
|
let df = match file.item().extension() {
|
||||||
@ -108,7 +107,7 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let df_tag = Tag {
|
let df_tag = Tag {
|
||||||
anchor: Some(AnchorLocation::File(file_name.to_string())),
|
anchor: Some(AnchorLocation::File(file_name)),
|
||||||
span: tag.span,
|
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 file: Tagged<PathBuf> = args.req(0)?;
|
||||||
|
|
||||||
let r = File::open(&file.item)
|
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))
|
.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 file: Tagged<PathBuf> = args.req(0)?;
|
||||||
|
|
||||||
let r = File::open(&file.item)
|
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))
|
.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 file: Tagged<PathBuf> = args.req(0)?;
|
||||||
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
||||||
let no_header: bool = args.has_flag("no_header");
|
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,
|
&d.tag,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
let delimiter = match d.item.chars().nth(0) {
|
let delimiter = match d.item.chars().next() {
|
||||||
Some(d) => d as u8,
|
Some(d) => d as u8,
|
||||||
None => unreachable!(),
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let id_col: Vec<Value> = args.req(0)?;
|
let id_col: Vec<Value> = args.req(0)?;
|
||||||
let val_col: Vec<Value> = args.req(1)?;
|
let val_col: Vec<Value> = args.req(1)?;
|
||||||
@ -67,7 +66,7 @@ fn check_column_datatypes<T: AsRef<str>>(
|
|||||||
cols: &[T],
|
cols: &[T],
|
||||||
col_span: &Span,
|
col_span: &Span,
|
||||||
) -> Result<(), ShellError> {
|
) -> Result<(), ShellError> {
|
||||||
if cols.len() == 0 {
|
if cols.is_empty() {
|
||||||
return Err(ShellError::labeled_error(
|
return Err(ShellError::labeled_error(
|
||||||
"Merge error",
|
"Merge error",
|
||||||
"empty column list",
|
"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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
// Extracting the pivot col from arguments
|
// Extracting the pivot col from arguments
|
||||||
let pivot_col: Tagged<String> = args.req(0)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
||||||
let fraction: Option<Tagged<f64>> = args.get_flag("fraction")?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let columns: Vec<Value> = args.req(0)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
let rows: Option<Tagged<usize>> = args.get_flag("n_rows")?;
|
||||||
let tail: bool = args.has_flag("tail");
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let offset: Tagged<usize> = args.req(0)?;
|
let offset: Tagged<usize> = args.req(0)?;
|
||||||
let size: Tagged<usize> = args.req(1)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let columns: Vec<Value> = args.req(0)?;
|
let columns: Vec<Value> = args.req(0)?;
|
||||||
let reverse = args.has_flag("reverse");
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||||
|
|
||||||
let rows = match rows {
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let file_name: Tagged<PathBuf> = args.req(0)?;
|
let file_name: Tagged<PathBuf> = args.req(0)?;
|
||||||
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
let delimiter: Option<Tagged<String>> = args.get_flag("delimiter")?;
|
||||||
let no_header: bool = args.has_flag("no_header");
|
let no_header: bool = args.has_flag("no_header");
|
||||||
@ -92,7 +91,7 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
&d.tag,
|
&d.tag,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
let delimiter = match d.item.chars().nth(0) {
|
let delimiter = match d.item.chars().next() {
|
||||||
Some(d) => d as u8,
|
Some(d) => d as u8,
|
||||||
None => unreachable!(),
|
None => unreachable!(),
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,6 @@ impl WholeStreamCommand for DataFrame {
|
|||||||
|
|
||||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let df = NuDataFrame::try_from_iter(args.input, &tag)?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let file_name: Tagged<PathBuf> = args.req(0)?;
|
let file_name: Tagged<PathBuf> = args.req(0)?;
|
||||||
|
|
||||||
let mut df = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?;
|
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> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let name: Option<Tagged<String>> = args.opt(0)?;
|
let name: Option<Tagged<String>> = args.opt(0)?;
|
||||||
let name = name.map(|v| v.item);
|
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
|
// Converts a Vec<Value> to a Vec<String> with a Span marking the whole
|
||||||
// location of the columns for error referencing
|
// location of the columns for error referencing
|
||||||
pub(crate) fn convert_columns<'columns>(
|
pub(crate) fn convert_columns(
|
||||||
columns: &'columns [Value],
|
columns: &[Value],
|
||||||
tag: &Tag,
|
tag: &Tag,
|
||||||
) -> Result<(Vec<String>, Span), ShellError> {
|
) -> Result<(Vec<String>, Span), ShellError> {
|
||||||
let mut col_span = match columns
|
let mut col_span = match columns
|
||||||
.iter()
|
.get(0)
|
||||||
.nth(0)
|
|
||||||
.map(|v| Span::new(v.tag.span.start(), v.tag.span.end()))
|
.map(|v| Span::new(v.tag.span.start(), v.tag.span.end()))
|
||||||
{
|
{
|
||||||
Some(span) => span,
|
Some(span) => span,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_engine::{evaluate_baseline_expr, EvaluatedCommandArgs, WholeStreamCommand};
|
use nu_engine::{evaluate_baseline_expr, WholeStreamCommand};
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
dataframe::NuDataFrame,
|
dataframe::NuDataFrame,
|
||||||
@ -44,7 +44,6 @@ impl WholeStreamCommand for DataFrame {
|
|||||||
|
|
||||||
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let block: CapturedBlock = args.req(0)?;
|
let block: CapturedBlock = args.req(0)?;
|
||||||
|
|
||||||
@ -65,21 +64,21 @@ fn command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.ok_or(ShellError::labeled_error(
|
.ok_or_else(|| {
|
||||||
"Expected a condition",
|
ShellError::labeled_error("Expected a condition", "expected a condition", &tag.span)
|
||||||
"expected a condition",
|
})?;
|
||||||
&tag.span,
|
|
||||||
))?;
|
|
||||||
|
|
||||||
let lhs = match &expression.left.expr {
|
let lhs = match &expression.left.expr {
|
||||||
Expression::FullColumnPath(p) => p.as_ref().tail.get(0),
|
Expression::FullColumnPath(p) => p.as_ref().tail.get(0),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
.ok_or(ShellError::labeled_error(
|
.ok_or_else(|| {
|
||||||
"No column name",
|
ShellError::labeled_error(
|
||||||
"Not a column name found in left hand side of comparison",
|
"No column name",
|
||||||
&expression.left.span,
|
"Not a column name found in left hand side of comparison",
|
||||||
))?;
|
&expression.left.span,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let (col_name, col_name_span) = match &lhs.unspanned {
|
let (col_name, col_name_span) = match &lhs.unspanned {
|
||||||
UnspannedPathMember::String(name) => Ok((name, &lhs.span)),
|
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)
|
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
|
// With the information extracted from the block we can filter the dataframe using
|
||||||
// polars operations
|
// polars operations
|
||||||
fn filter_dataframe(
|
fn filter_dataframe(
|
||||||
mut args: EvaluatedCommandArgs,
|
mut args: CommandArgs,
|
||||||
col_name: &str,
|
col_name: &str,
|
||||||
col_name_span: &Span,
|
col_name_span: &Span,
|
||||||
rhs: &Value,
|
rhs: &Value,
|
||||||
@ -212,6 +211,6 @@ fn filter_dataframe(
|
|||||||
|
|
||||||
Ok(OutputStream::one(NuDataFrame::dataframe_to_value(
|
Ok(OutputStream::one(NuDataFrame::dataframe_to_value(
|
||||||
res,
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let mut args = args.evaluate_once()?;
|
|
||||||
let value: Value = args.req(0)?;
|
let value: Value = args.req(0)?;
|
||||||
let name: Tagged<String> = args.req(2)?;
|
let name: Tagged<String> = args.req(2)?;
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ impl WholeStreamCommand for Date {
|
|||||||
|
|
||||||
pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn format(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let format: Tagged<String> = args.req(0)?;
|
let format: Tagged<String> = args.req(0)?;
|
||||||
let table: Option<bool> = args.get_flag("table")?;
|
let table: Option<bool> = args.get_flag("table")?;
|
||||||
|
@ -41,8 +41,7 @@ impl WholeStreamCommand for Date {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn list_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn list_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
let tag = args.call_info.name_tag;
|
||||||
let tag = args.call_info.name_tag.clone();
|
|
||||||
|
|
||||||
let list = TZ_VARIANTS.iter().map(move |tz| {
|
let list = TZ_VARIANTS.iter().map(move |tz| {
|
||||||
let mut entries = IndexMap::new();
|
let mut entries = IndexMap::new();
|
||||||
|
@ -31,8 +31,6 @@ pub fn date_now(tag: &Tag) -> Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn now(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let value = date_now(&args.call_info.name_tag);
|
let value = date_now(&args.call_info.name_tag);
|
||||||
|
|
||||||
Ok(OutputStream::one(value))
|
Ok(OutputStream::one(value))
|
||||||
|
@ -34,7 +34,6 @@ impl WholeStreamCommand for Date {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_table(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn to_table(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.clone();
|
||||||
let input = if args.input.is_empty() {
|
let input = if args.input.is_empty() {
|
||||||
InputStream::one(crate::commands::date::now::date_now(&tag))
|
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> {
|
fn to_timezone(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let timezone: Tagged<String> = args.req(0)?;
|
let timezone: Tagged<String> = args.req(0)?;
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ impl WholeStreamCommand for Debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn debug_value(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn debug_value(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let raw = args.has_flag("raw");
|
let raw = args.has_flag("raw");
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ impl WholeStreamCommand for Default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn default(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn default(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column: Tagged<String> = args.req(0)?;
|
let column: Tagged<String> = args.req(0)?;
|
||||||
let value: Value = args.req(1)?;
|
let value: Value = args.req(1)?;
|
||||||
|
|
||||||
|
@ -59,11 +59,10 @@ impl WholeStreamCommand for Do {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn do_(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
let external_redirection = args.call_info.args.external_redirection;
|
||||||
|
|
||||||
let context = EvaluationContext::from_args(&raw_args);
|
let context = args.context().clone();
|
||||||
let args = raw_args.evaluate_once()?;
|
|
||||||
let do_args = DoArgs {
|
let do_args = DoArgs {
|
||||||
block: args.req(0)?,
|
block: args.req(0)?,
|
||||||
ignore_errors: args.has_flag("ignore-errors"),
|
ignore_errors: args.has_flag("ignore-errors"),
|
||||||
|
@ -43,7 +43,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let columns: Option<Tagged<u64>> = args.opt(0)?;
|
let columns: Option<Tagged<u64>> = args.opt(0)?;
|
||||||
|
|
||||||
let to_drop = if let Some(quantity) = columns {
|
let to_drop = if let Some(quantity) = columns {
|
||||||
|
@ -47,7 +47,6 @@ impl WholeStreamCommand for Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn drop(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let rows: Option<Tagged<u64>> = args.opt(0)?;
|
let rows: Option<Tagged<u64>> = args.opt(0)?;
|
||||||
let v: Vec<_> = args.input.into_vec();
|
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 = args.ctrl_c();
|
||||||
let ctrl_c_copy = ctrl_c.clone();
|
let ctrl_c_copy = ctrl_c.clone();
|
||||||
|
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let args = DuArgs {
|
let args = DuArgs {
|
||||||
path: args.opt(0)?,
|
path: args.opt(0)?,
|
||||||
all: args.has_flag("all"),
|
all: args.has_flag("all"),
|
||||||
|
@ -114,10 +114,9 @@ pub(crate) fn make_indexed_item(index: usize, item: Value) -> Value {
|
|||||||
dict.into_value()
|
dict.into_value()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn each(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn each(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
let context = Arc::new(args.context.clone());
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
let external_redirection = args.call_info.args.external_redirection;
|
||||||
let args = raw_args.evaluate_once()?;
|
|
||||||
|
|
||||||
let block: CapturedBlock = args.req(0)?;
|
let block: CapturedBlock = args.req(0)?;
|
||||||
let numbered: bool = args.has_flag("numbered");
|
let numbered: bool = args.has_flag("numbered");
|
||||||
|
@ -37,10 +37,9 @@ impl WholeStreamCommand for EachGroup {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
let context = Arc::new(args.context.clone());
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
let external_redirection = args.call_info.args.external_redirection;
|
||||||
let args = raw_args.evaluate_once()?;
|
|
||||||
|
|
||||||
let group_size: Tagged<usize> = args.req(0)?;
|
let group_size: Tagged<usize> = args.req(0)?;
|
||||||
let block: CapturedBlock = args.req(1)?;
|
let block: CapturedBlock = args.req(1)?;
|
||||||
|
@ -41,11 +41,10 @@ impl WholeStreamCommand for EachWindow {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn run(&self, mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
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 window_size: Tagged<usize> = args.req(0)?;
|
||||||
let block: CapturedBlock = args.req(1)?;
|
let block: CapturedBlock = args.req(1)?;
|
||||||
let stride: Option<Tagged<usize>> = args.get_flag("stride")?;
|
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> {
|
fn echo(args: CommandArgs) -> Result<InputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let rest: Vec<Value> = args.rest(0)?;
|
let rest: Vec<Value> = args.rest(0)?;
|
||||||
|
|
||||||
let stream = rest.into_iter().map(|i| match i.as_string() {
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let name_tag = Arc::new(args.call_info.name_tag.clone());
|
let name_tag = Arc::new(args.call_info.name_tag.clone());
|
||||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let block: Option<CapturedBlock> = args.get_flag("block")?;
|
let block: Option<CapturedBlock> = args.get_flag("block")?;
|
||||||
let columns: Vec<ColumnPath> = args.rest(0)?;
|
let columns: Vec<ColumnPath> = args.rest(0)?;
|
||||||
|
|
||||||
|
@ -74,7 +74,6 @@ fn enter(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||||||
let context = args.context.clone();
|
let context = args.context.clone();
|
||||||
let scope = args.scope().clone();
|
let scope = args.scope().clone();
|
||||||
let path = args.context.shell_manager.path();
|
let path = args.context.shell_manager.path();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let location: Tagged<PathBuf> = args.req(0)?;
|
let location: Tagged<PathBuf> = args.req(0)?;
|
||||||
let encoding: Option<Tagged<String>> = args.get_flag("encoding")?;
|
let encoding: Option<Tagged<String>> = args.get_flag("encoding")?;
|
||||||
|
@ -56,8 +56,6 @@ impl WholeStreamCommand for Every {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn every(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn every(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let stride: u64 = args.req(0)?;
|
let stride: u64 = args.req(0)?;
|
||||||
let skip: bool = args.has_flag("skip");
|
let skip: bool = args.has_flag("skip");
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
@ -64,7 +64,6 @@ fn exec(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let args = ExecArgs {
|
let args = ExecArgs {
|
||||||
command: args.req(0)?,
|
command: args.req(0)?,
|
||||||
|
@ -44,15 +44,13 @@ impl WholeStreamCommand for Exit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
pub fn exit(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
let code = if let Some(value) = args.opt::<i64>(0)? {
|
||||||
|
value as i32
|
||||||
let code = if let Some(value) = args.call_info.args.nth(0) {
|
|
||||||
value.as_i32()?
|
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
let command_action = if args.call_info.args.has("now") {
|
let command_action = if args.has_flag("now") {
|
||||||
CommandAction::Exit(code)
|
CommandAction::Exit(code)
|
||||||
} else {
|
} else {
|
||||||
CommandAction::LeaveShell(code)
|
CommandAction::LeaveShell(code)
|
||||||
|
@ -47,7 +47,6 @@ impl WholeStreamCommand for First {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn first(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn first(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ impl WholeStreamCommand for Command {
|
|||||||
|
|
||||||
fn flatten(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn flatten(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let columns: Vec<Tagged<String>> = args.rest(0)?;
|
let columns: Vec<Tagged<String>> = args.rest(0)?;
|
||||||
let input = args.input;
|
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> {
|
fn for_in(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
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 numbered: bool = raw_args.call_info.switch_present("numbered");
|
||||||
let positional = raw_args
|
let positional = raw_args
|
||||||
.call_info
|
.call_info
|
||||||
|
@ -40,7 +40,6 @@ impl WholeStreamCommand for Format {
|
|||||||
|
|
||||||
fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn format_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let ctx = Arc::new(EvaluationContext::from_args(&args));
|
let ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let pattern: Tagged<String> = args.req(0)?;
|
let pattern: Tagged<String> = args.req(0)?;
|
||||||
|
|
||||||
let format_pattern = format(&pattern);
|
let format_pattern = format(&pattern);
|
||||||
|
@ -83,9 +83,7 @@ fn process_row(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filesize(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn filesize(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = raw_args.evaluate_once()?;
|
|
||||||
|
|
||||||
let field: ColumnPath = args.req(0)?;
|
let field: ColumnPath = args.req(0)?;
|
||||||
let format: Tagged<String> = args.req(1)?;
|
let format: Tagged<String> = args.req(1)?;
|
||||||
let field = Arc::new(field);
|
let field = Arc::new(field);
|
||||||
|
@ -62,7 +62,6 @@ impl WholeStreamCommand for FromCsv {
|
|||||||
|
|
||||||
fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn from_csv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let noheaders = args.has_flag("noheaders");
|
let noheaders = args.has_flag("noheaders");
|
||||||
let separator: Option<Value> = args.get_flag("separator")?;
|
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> {
|
fn from_eml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let preview_body: Option<Tagged<usize>> = args.get_flag("preview-body")?;
|
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> {
|
fn from_ics(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ pub fn from_ini_string_to_value(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn from_ini(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
let concat_string = input.collect_string(tag.clone())?;
|
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> {
|
fn from_json(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
|
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let objects = args.has_flag("objects");
|
let objects = args.has_flag("objects");
|
||||||
|
|
||||||
let concat_string = args.input.collect_string(name_tag.clone())?;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let span = tag.span;
|
let span = tag.span;
|
||||||
|
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let mut sel_sheets = vec![];
|
let mut sel_sheets = vec![];
|
||||||
|
|
||||||
if let Some(s) = args.call_info.args.get("sheets") {
|
if let Some(columns) = args.get_flag::<Vec<Value>>("sheets")? {
|
||||||
if let UntaggedValue::Table(columns) = s.value.clone() {
|
sel_sheets = convert_columns(columns.as_slice())?;
|
||||||
sel_sheets = convert_columns(columns.as_slice())?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bytes = args.input.collect_binary(tag.clone())?;
|
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> {
|
fn from_ssv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let noheaders = args.has_flag("noheaders");
|
let noheaders = args.has_flag("noheaders");
|
||||||
let aligned_columns = args.has_flag("aligned-columns");
|
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> {
|
pub fn from_toml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ impl WholeStreamCommand for FromTsv {
|
|||||||
|
|
||||||
fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn from_tsv(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let noheaders = args.has_flag("noheaders");
|
let noheaders = args.has_flag("noheaders");
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ impl WholeStreamCommand for FromUrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn from_url(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ impl WholeStreamCommand for FromVcf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn from_vcf(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
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 tag = args.call_info.name_tag.clone();
|
||||||
let span = tag.span;
|
let span = tag.span;
|
||||||
|
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let mut sel_sheets = vec![];
|
let mut sel_sheets = vec![];
|
||||||
|
|
||||||
if let Some(s) = args.call_info.args.get("sheets") {
|
if let Some(columns) = args.get_flag::<Vec<Value>>("sheets")? {
|
||||||
if let UntaggedValue::Table(columns) = s.value.clone() {
|
sel_sheets = convert_columns(columns.as_slice())?;
|
||||||
sel_sheets = convert_columns(columns.as_slice())?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = args.input.collect_binary(tag.clone())?;
|
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> {
|
fn from_xml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
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> {
|
fn from_yaml(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let tag = args.name_tag();
|
let tag = args.name_tag();
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ impl WholeStreamCommand for Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
pub fn get(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||||
let mut input = args.input;
|
let mut input = args.input;
|
||||||
|
|
||||||
|
@ -126,7 +126,6 @@ enum Grouper {
|
|||||||
pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn group_by(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let grouper = args.opt(0)?;
|
let grouper = args.opt(0)?;
|
||||||
let values: Vec<Value> = args.input.collect();
|
let values: Vec<Value> = args.input.collect();
|
||||||
|
@ -54,7 +54,6 @@ enum GroupByColumn {
|
|||||||
|
|
||||||
pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
pub fn group_by_date(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column_name: Option<Tagged<String>> = args.opt(0)?;
|
let column_name: Option<Tagged<String>> = args.opt(0)?;
|
||||||
let format: Option<Tagged<String>> = args.get_flag("format")?;
|
let format: Option<Tagged<String>> = args.get_flag("format")?;
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
|
|
||||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let name_tag = args.call_info.name_tag.clone();
|
let name_tag = args.call_info.name_tag.clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let encode = args.has_flag("encode");
|
let encode = args.has_flag("encode");
|
||||||
let decode = args.has_flag("decode");
|
let decode = args.has_flag("decode");
|
||||||
|
@ -50,7 +50,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn operate(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||||
|
|
||||||
Ok(args
|
Ok(args
|
||||||
|
@ -34,7 +34,6 @@ impl WholeStreamCommand for Help {
|
|||||||
fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn help(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
let name = args.call_info.name_tag.clone();
|
||||||
let scope = args.scope().clone();
|
let scope = args.scope().clone();
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
let rest: Vec<Tagged<String>> = args.rest(0)?;
|
||||||
|
|
||||||
|
@ -59,21 +59,10 @@ impl WholeStreamCommand for Histogram {
|
|||||||
|
|
||||||
pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
pub fn histogram(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let name = args.call_info.name_tag.clone();
|
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.rest::<ColumnPath>(0)?;
|
||||||
|
let evaluate_with = args.get_flag::<ColumnPath>("use")?.map(evaluator);
|
||||||
let mut columns = args
|
let values: Vec<Value> = args.input.collect();
|
||||||
.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 column_grouper = if !columns.is_empty() {
|
let column_grouper = if !columns.is_empty() {
|
||||||
columns
|
columns
|
||||||
|
@ -28,7 +28,6 @@ impl WholeStreamCommand for History {
|
|||||||
fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn history(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let tag = args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let ctx = EvaluationContext::from_args(&args);
|
let ctx = EvaluationContext::from_args(&args);
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let clear = args.has_flag("clear");
|
let clear = args.has_flag("clear");
|
||||||
|
|
||||||
|
@ -57,12 +57,11 @@ impl WholeStreamCommand for If {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn if_command(raw_args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn if_command(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let tag = raw_args.call_info.name_tag.clone();
|
let tag = args.call_info.name_tag.clone();
|
||||||
let external_redirection = raw_args.call_info.args.external_redirection;
|
let external_redirection = args.call_info.args.external_redirection;
|
||||||
let context = Arc::new(EvaluationContext::from_args(&raw_args));
|
let context = Arc::new(args.context.clone());
|
||||||
|
|
||||||
let args = raw_args.evaluate_once()?;
|
|
||||||
let condition: CapturedBlock = args.req(0)?;
|
let condition: CapturedBlock = args.req(0)?;
|
||||||
let then_case: CapturedBlock = args.req(1)?;
|
let then_case: CapturedBlock = args.req(1)?;
|
||||||
let else_case: CapturedBlock = args.req(2)?;
|
let else_case: CapturedBlock = args.req(2)?;
|
||||||
|
@ -154,7 +154,6 @@ fn process_row(
|
|||||||
|
|
||||||
fn insert(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn insert(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||||
let context = Arc::new(EvaluationContext::from_args(&args));
|
let context = Arc::new(EvaluationContext::from_args(&args));
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column: ColumnPath = args.req(0)?;
|
let column: ColumnPath = args.req(0)?;
|
||||||
let value: Value = args.req(1)?;
|
let value: Value = args.req(1)?;
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
@ -113,7 +113,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_binary(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn into_binary(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let skip: Option<Value> = args.get_flag("skip")?;
|
let skip: Option<Value> = args.get_flag("skip")?;
|
||||||
let bytes: Option<Value> = args.get_flag("bytes")?;
|
let bytes: Option<Value> = args.get_flag("bytes")?;
|
||||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||||
|
@ -79,7 +79,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn into_int(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||||
|
|
||||||
Ok(args
|
Ok(args
|
||||||
|
@ -81,8 +81,6 @@ impl WholeStreamCommand for SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn into_string(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn into_string(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
|
|
||||||
let decimals: Option<Tagged<u64>> = args.get_flag("decimals")?;
|
let decimals: Option<Tagged<u64>> = args.get_flag("decimals")?;
|
||||||
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
let column_paths: Vec<ColumnPath> = args.rest(0)?;
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ impl WholeStreamCommand for Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once()?;
|
|
||||||
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
let rows: Option<Tagged<usize>> = args.opt(0)?;
|
||||||
|
|
||||||
let rows_desired = if let Some(quantity) = rows {
|
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 New Issue
Block a user