diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 66422fadba..f1f5347da5 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -31,6 +31,8 @@ impl Command for Where { let cond = &call.positional[0]; let span = call.head; + let metadata = input.metadata(); + let block_id = cond .as_row_condition_block() .ok_or_else(|| ShellError::TypeMismatch("expected row condition".to_owned(), span))?; @@ -41,21 +43,24 @@ impl Command for Where { let block = engine_state.get_block(block_id).clone(); let mut stack = stack.collect_captures(&block.captures); - 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()); + 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()); + } } - } - let result = eval_block(&engine_state, &mut stack, &block, PipelineData::new(span)); + let result = + eval_block(&engine_state, &mut stack, &block, PipelineData::new(span)); - match result { - Ok(result) => result.into_value(span).is_true(), - _ => false, - } - }, - ctrlc, - ) + match result { + Ok(result) => result.into_value(span).is_true(), + _ => false, + } + }, + ctrlc, + ) + .map(|x| x.set_metadata(metadata)) } } diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index 75fc9799e5..c5772ada33 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -65,6 +65,17 @@ impl PipelineData { } } + pub fn set_metadata(mut self, metadata: Option) -> Self { + match &mut self { + PipelineData::ListStream(_, x) => *x = metadata, + PipelineData::ByteStream(_, _, x) => *x = metadata, + PipelineData::StringStream(_, _, x) => *x = metadata, + PipelineData::Value(_, x) => *x = metadata, + } + + self + } + pub fn into_value(self, span: Span) -> Value { match self { PipelineData::Value(Value::Nothing { .. }, ..) => Value::nothing(span),