mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
parent
8b9a8daa1d
commit
c3535b5c67
5 changed files with 49 additions and 6 deletions
|
@ -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<InputStream, ShellError> {
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -33,6 +33,19 @@ impl WholeStreamCommand for Date {
|
|||
) -> Result<OutputStream, ShellError> {
|
||||
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<T: TimeZone>(dt: DateTime<T>, tag: Tag) -> Value
|
||||
|
|
|
@ -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]");
|
||||
}
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue