diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index 25de200964..1a1b9eadd9 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -2,7 +2,8 @@ use nu_engine::{eval_block, CallExt}; use nu_protocol::{ ast::Call, engine::{CaptureBlock, Command, EngineState, Stack}, - Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, + SyntaxShape, Value, }; #[derive(Clone)] @@ -87,9 +88,9 @@ impl Command for Find { input: PipelineData, ) -> Result { let span = call.head; - let ctrlc = engine_state.ctrlc.clone(); let engine_state = engine_state.clone(); + let metadata = input.metadata(); match call.get_flag::(&engine_state, stack, "predicate")? { Some(predicate) => { @@ -114,17 +115,22 @@ impl Command for Find { stack.add_var(var_id, value.clone()); } - eval_block(&engine_state, &mut stack, &block, PipelineData::new(span)) - .map_or(false, |pipeline_data| { - pipeline_data.into_value(span).is_true() - }) + eval_block( + &engine_state, + &mut stack, + &block, + PipelineData::new_with_metadata(metadata.clone(), span), + ) + .map_or(false, |pipeline_data| { + pipeline_data.into_value(span).is_true() + }) }, ctrlc, ) } None => { let terms = call.rest::(&engine_state, stack, 0)?; - input.filter( + let pipe = input.filter( move |value| { terms.iter().any(|term| match value { Value::Bool { .. } @@ -152,7 +158,13 @@ impl Command for Find { }) }, ctrlc, - ) + )?; + match metadata { + Some(m) => { + Ok(pipe.into_pipeline_data_with_metadata(m, engine_state.ctrlc.clone())) + } + None => Ok(pipe), + } } } } diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index c5772ada33..84ca08968e 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -56,6 +56,10 @@ impl PipelineData { PipelineData::Value(Value::Nothing { span }, None) } + pub fn new_with_metadata(metadata: Option, span: Span) -> PipelineData { + PipelineData::Value(Value::Nothing { span }, metadata) + } + pub fn metadata(&self) -> Option { match self { PipelineData::ListStream(_, x) => x.clone(),