From a1b30fda7524e2c2753b602535075363decbb3c6 Mon Sep 17 00:00:00 2001 From: Odin Dutton Date: Wed, 28 Aug 2019 13:06:22 +1000 Subject: [PATCH] Remove sort-by --reverse flag Prefer `ls | sort-by size | reverse` over `ls | sort-by size --reverse`. --- README.md | 2 +- src/commands/sort_by.rs | 13 +++---------- tests/filters_test.rs | 11 ----------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index ddb6bc348d..b44121d271 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat | pick ...columns | Down-select table to only these columns | | reject ...columns | Remove the given columns from the table | | get column-or-column-path | Open given cells as text | -| sort-by ...columns (--reverse) | Sort by the given columns | +| sort-by ...columns | Sort by the given columns | | where condition | Filter table to match the condition | | inc (field) | Increment a value or version. Optional use the field of a table | | add field value | Add a new field to the table | diff --git a/src/commands/sort_by.rs b/src/commands/sort_by.rs index c726dbedc0..c538fdf97f 100644 --- a/src/commands/sort_by.rs +++ b/src/commands/sort_by.rs @@ -7,7 +7,6 @@ pub struct SortBy; #[derive(Deserialize)] pub struct SortByArgs { rest: Vec>, - reverse: bool, } impl WholeStreamCommand for SortBy { @@ -24,14 +23,12 @@ impl WholeStreamCommand for SortBy { } fn signature(&self) -> Signature { - Signature::build("sort-by") - .rest(SyntaxType::String) - .switch("reverse") + Signature::build("sort-by").rest(SyntaxType::String) } } fn sort_by( - SortByArgs { reverse, rest }: SortByArgs, + SortByArgs { rest }: SortByArgs, mut context: RunnableContext, ) -> Result { Ok(OutputStream::new(async_stream_block! { @@ -42,11 +39,7 @@ fn sort_by( .map(|f| item.get_data_by_key(f).map(|i| i.clone())) .collect::>>>() }; - if reverse { - vec.sort_by_cached_key(|item| std::cmp::Reverse(calc_key(item))); - } else { - vec.sort_by_cached_key(calc_key); - }; + vec.sort_by_cached_key(calc_key); for item in vec { yield item.into(); diff --git a/tests/filters_test.rs b/tests/filters_test.rs index d8976c1cc1..f5b8ebb772 100644 --- a/tests/filters_test.rs +++ b/tests/filters_test.rs @@ -215,17 +215,6 @@ fn can_sort_by_column() { assert_eq!(output, "description"); } -#[test] -fn can_sort_by_column_reverse() { - nu!( - output, - cwd("tests/fixtures/formats"), - r#"open cargo_sample.toml --raw | lines | skip 1 | first 4 | split-column "=" | sort-by Column1 --reverse | skip 1 | first 1 | get Column1 | trim | echo $it"# - ); - - assert_eq!(output, "name"); -} - #[test] fn can_split_by_column() { nu!(