diff --git a/crates/nu-cli/src/commands/classified/expr.rs b/crates/nu-cli/src/commands/classified/expr.rs index d0c3027cb7..8a10aaf4b6 100644 --- a/crates/nu-cli/src/commands/classified/expr.rs +++ b/crates/nu-cli/src/commands/classified/expr.rs @@ -3,6 +3,7 @@ use crate::prelude::*; use log::{log_enabled, trace}; +use futures::stream::once; use nu_errors::ShellError; use nu_protocol::hir::SpannedExpression; use nu_protocol::Scope; @@ -10,7 +11,7 @@ use nu_protocol::Scope; pub(crate) fn run_expression_block( expr: SpannedExpression, context: &mut Context, - input: InputStream, + _input: InputStream, scope: &Scope, ) -> Result { if log_enabled!(log::Level::Trace) { @@ -20,10 +21,7 @@ pub(crate) fn run_expression_block( let scope = scope.clone(); let registry = context.registry().clone(); - let stream = input.map(move |row| { - let scope = scope.clone().set_it(row); - evaluate_baseline_expr(&expr, ®istry, &scope) - }); + let output = evaluate_baseline_expr(&expr, ®istry, &scope)?; - Ok(stream.to_input_stream()) + Ok(once(async { Ok(output) }).to_input_stream()) } diff --git a/crates/nu-cli/src/commands/date.rs b/crates/nu-cli/src/commands/date.rs index 45b730bd5c..c12a5e6ccc 100644 --- a/crates/nu-cli/src/commands/date.rs +++ b/crates/nu-cli/src/commands/date.rs @@ -33,6 +33,19 @@ impl WholeStreamCommand for Date { ) -> Result { date(args, registry) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Get the current local time and date", + example: "date", + }, + Example { + description: "Get the current UTC time and date", + example: "date --utc", + }, + ] + } } pub fn date_to_value(dt: DateTime, tag: Tag) -> Value diff --git a/crates/nu-cli/tests/commands/cal.rs b/crates/nu-cli/tests/commands/cal.rs index 82875ab7ce..16b0c0303e 100644 --- a/crates/nu-cli/tests/commands/cal.rs +++ b/crates/nu-cli/tests/commands/cal.rs @@ -51,3 +51,15 @@ fn cal_rows_in_2020() { assert!(actual.out.contains("62")); } + +#[test] +fn cal_sees_pipeline_year() { + let actual = nu!( + cwd: ".", pipeline( + r#" + echo 1020 | cal --full-year $it | get monday | first 3 | to json + "# + )); + + assert_eq!(actual.out, "[3,10,17]"); +} diff --git a/crates/nu-cli/tests/commands/math.rs b/crates/nu-cli/tests/commands/math.rs index ee513fd312..9822b48f9e 100644 --- a/crates/nu-cli/tests/commands/math.rs +++ b/crates/nu-cli/tests/commands/math.rs @@ -108,6 +108,18 @@ fn duration_math() { assert_eq!(actual.out, "8:00:00:00"); } +#[test] +fn it_math() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + echo 1020 | = $it + 10 + "# + )); + + assert_eq!(actual.out, "1030"); +} + #[test] fn compound_comparison() { let actual = nu!( diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 5986f6171c..e72cf7fc2f 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -92,6 +92,14 @@ impl ClassifiedCommand { } } + if let Some(named) = &command.args.named { + for arg in named.iter() { + if let NamedValue::Value(_, value) = arg.1 { + result = result || value.has_shallow_it_usage(); + } + } + } + result } ClassifiedCommand::Expr(expr) => expr.has_shallow_it_usage(),