From 2e68e6ddbf85178881055af4924d9ede7ece0cac Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sun, 29 Oct 2023 08:22:20 -0500 Subject: [PATCH] allow `sort-by` to work with records (#10870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR restores and old functionality that must of been broken with the input_output_types() updating. It allows commands like this to work again. ```nushell open $nu.history-path | get history.command_line | split column ' ' cmd | group-by cmd --to-table | update items {|u| $u.items | length} | sort-by items -r | first 10 | table -n 1 ``` output ``` ╭#─┬group─┬items╮ │1 │exit │ 3004│ │2 │ls │ 2591│ │3 │git │ 1678│ │4 │help │ 1549│ │5 │open │ 1374│ │6 │cd │ 1186│ │7 │cargo │ 944│ │8 │let │ 784│ │9 │source│ 755│ │10│z │ 486│ ╰#─┴group─┴items╯ ``` # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/filters/sort_by.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filters/sort_by.rs b/crates/nu-command/src/filters/sort_by.rs index 0e5110765d..e4c1821263 100644 --- a/crates/nu-command/src/filters/sort_by.rs +++ b/crates/nu-command/src/filters/sort_by.rs @@ -17,11 +17,12 @@ impl Command for SortBy { fn signature(&self) -> nu_protocol::Signature { Signature::build("sort-by") .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), + (Type::Record(vec![]), Type::Table(vec![])), + (Type::Table(vec![]), Type::Table(vec![])), ]) .rest("columns", SyntaxShape::Any, "the column(s) to sort by") .switch("reverse", "Sort in reverse order", Some('r'))