From 19e76332fa5695d1158b0d681a1bf5a99c57d962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20B=C3=BCsch?= Date: Fri, 19 Jan 2024 00:57:21 +1100 Subject: [PATCH] fix: items doesn't support lazy records (#11567) # Description Implement support for lazy records for `items`, the same way `columns` or `values` do. # User-Facing Changes Something like `sys | items {|k,v| $"($k): ($v)"}` used to fail with an error. Now it works as expected. # Tests + Formatting # After Submitting --- crates/nu-command/src/filters/items.rs | 39 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/nu-command/src/filters/items.rs b/crates/nu-command/src/filters/items.rs index ea84666532..0433fdee24 100644 --- a/crates/nu-command/src/filters/items.rs +++ b/crates/nu-command/src/filters/items.rs @@ -92,24 +92,39 @@ impl Command for Items { }; match input { PipelineData::Empty => Ok(PipelineData::Empty), - PipelineData::Value(Value::Record { val, .. }, ..) => Ok(val - .into_iter() - .map_while(run_for_each_item) - .into_pipeline_data(ctrlc)), - // Errors + PipelineData::Value(v, ..) => match v { + Value::Record { val, .. } => Ok(val + .into_iter() + .map_while(run_for_each_item) + .into_pipeline_data(ctrlc)), + Value::LazyRecord { val, .. } => { + let record = match val.collect()? { + Value::Record { val, .. } => val, + _ => Err(ShellError::NushellFailedSpanned { + msg: "`LazyRecord::collect()` promises `Value::Record`".into(), + label: "Violating lazy record found here".into(), + span, + })?, + }; + Ok(record + .into_iter() + .map_while(run_for_each_item) + .into_pipeline_data(ctrlc)) + } + Value::Error { error, .. } => Err(*error), + other => Err(ShellError::OnlySupportsThisInputType { + exp_input_type: "record".into(), + wrong_type: other.get_type().to_string(), + dst_span: call.head, + src_span: other.span(), + }), + }, PipelineData::ListStream(..) => Err(ShellError::OnlySupportsThisInputType { exp_input_type: "record".into(), wrong_type: "stream".into(), dst_span: call.head, src_span: input_span, }), - PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error), - PipelineData::Value(other, ..) => Err(ShellError::OnlySupportsThisInputType { - exp_input_type: "record".into(), - wrong_type: other.get_type().to_string(), - dst_span: call.head, - src_span: other.span(), - }), PipelineData::ExternalStream { .. } => Err(ShellError::OnlySupportsThisInputType { exp_input_type: "record".into(), wrong_type: "raw data".into(),