mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:14:44 +02:00
Improve comparison errors (#4541)
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
use nu_engine::{eval_block_with_redirect, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, SyntaxShape, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Where;
|
||||
@ -39,29 +41,35 @@ impl Command for Where {
|
||||
let ctrlc = engine_state.ctrlc.clone();
|
||||
let engine_state = engine_state.clone();
|
||||
|
||||
input
|
||||
.filter(
|
||||
move |value| {
|
||||
if let Some(var) = block.signature.get_positional(0) {
|
||||
if let Some(var_id) = &var.var_id {
|
||||
stack.add_var(*var_id, value.clone());
|
||||
Ok(input
|
||||
.into_iter()
|
||||
.filter_map(move |value| {
|
||||
if let Some(var) = block.signature.get_positional(0) {
|
||||
if let Some(var_id) = &var.var_id {
|
||||
stack.add_var(*var_id, value.clone());
|
||||
}
|
||||
}
|
||||
let result = eval_block_with_redirect(
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
&block,
|
||||
PipelineData::new(span),
|
||||
);
|
||||
|
||||
match result {
|
||||
Ok(result) => {
|
||||
let result = result.into_value(span);
|
||||
if result.is_true() {
|
||||
Some(value)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
let result = eval_block_with_redirect(
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
&block,
|
||||
PipelineData::new(span),
|
||||
);
|
||||
|
||||
match result {
|
||||
Ok(result) => result.into_value(span).is_true(),
|
||||
_ => false,
|
||||
}
|
||||
},
|
||||
ctrlc,
|
||||
)
|
||||
.map(|x| x.set_metadata(metadata))
|
||||
Err(err) => Some(Value::Error { error: err }),
|
||||
}
|
||||
})
|
||||
.into_pipeline_data(ctrlc))
|
||||
.map(|x| x.set_metadata(metadata))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -127,7 +127,7 @@ fn converts_to_int() {
|
||||
| into int number_as_string
|
||||
| rename number
|
||||
| where number == 1
|
||||
| get number
|
||||
| get number.0
|
||||
|
||||
"#
|
||||
));
|
||||
|
Reference in New Issue
Block a user