From 29e809ad77618d6ea72bfc2573f9f2dc8761ad50 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:57:29 -0500 Subject: [PATCH] allow `values` command to support `LazyRecord`s (#10418) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR allows the `values` command to support lazy records. closes https://github.com/nushell/nushell/issues/10417 ### Before ```nushell sys | values Error: nu::shell::only_supports_this_input_type × Input type not supported. ╭─[entry #1:1:1] 1 │ sys | values · ─┬─ ───┬── · │ ╰── only record or table input data is supported · ╰── input type: record>, cpu: table, disks: table, mem: record, temp: list, net: table> ╰──── ``` ### After ```nushell ❯ sys | values ╭─┬─────────────────╮ │0│{record 8 fields}│ │1│[table 16 rows] │ │2│[table 1 row] │ │3│{record 7 fields}│ │4│[list 0 items] │ │5│[table 5 rows] │ ╰─┴─────────────────╯ ``` # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/filters/values.rs | 7 +++++++ crates/nu-command/tests/commands/insert.rs | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/nu-command/src/filters/values.rs b/crates/nu-command/src/filters/values.rs index 023cf6c8e..5a6be33b7 100644 --- a/crates/nu-command/src/filters/values.rs +++ b/crates/nu-command/src/filters/values.rs @@ -166,6 +166,13 @@ fn values( Value::Record { val, .. } => { Ok(val.vals.into_pipeline_data(ctrlc).set_metadata(metadata)) } + Value::LazyRecord { val, .. } => Ok(val + .collect()? + .as_record()? + .vals + .clone() + .into_pipeline_data(ctrlc) + .set_metadata(metadata)), // Propagate errors Value::Error { error, .. } => Err(*error), other => Err(ShellError::OnlySupportsThisInputType { diff --git a/crates/nu-command/tests/commands/insert.rs b/crates/nu-command/tests/commands/insert.rs index 50a881053..8ffc265f9 100644 --- a/crates/nu-command/tests/commands/insert.rs +++ b/crates/nu-command/tests/commands/insert.rs @@ -79,3 +79,11 @@ fn insert_support_lazy_record() { nu!(r#"let x = (lazy make -c ["h"] -g {|a| $a | str upcase}); $x | insert a 10 | get a"#); assert_eq!(actual.out, "10"); } + +#[test] +fn lazy_record_test_values() { + let actual = nu!( + r#"lazy make --columns ["haskell", "futures", "nushell"] --get-value { |lazything| $lazything + "!" } | values | length"# + ); + assert_eq!(actual.out, "3"); +}