mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 23:23:12 +01:00
Preserve metatdata in where (#618)
This commit is contained in:
parent
c8330523c8
commit
832a801c11
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,17 @@ impl PipelineData {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_metadata(mut self, metadata: Option<PipelineMetadata>) -> 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),
|
||||
|
Loading…
Reference in New Issue
Block a user