forked from extern/nushell
Remove sort-by --reverse flag
Prefer `ls | sort-by size | reverse` over `ls | sort-by size --reverse`.
This commit is contained in:
parent
8e95508353
commit
a1b30fda75
@ -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 |
|
||||
|
@ -7,7 +7,6 @@ pub struct SortBy;
|
||||
#[derive(Deserialize)]
|
||||
pub struct SortByArgs {
|
||||
rest: Vec<Tagged<String>>,
|
||||
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<OutputStream, ShellError> {
|
||||
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::<Vec<Option<Tagged<Value>>>>()
|
||||
};
|
||||
if reverse {
|
||||
vec.sort_by_cached_key(|item| std::cmp::Reverse(calc_key(item)));
|
||||
} else {
|
||||
vec.sort_by_cached_key(calc_key);
|
||||
};
|
||||
|
||||
for item in vec {
|
||||
yield item.into();
|
||||
|
@ -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!(
|
||||
|
Loading…
Reference in New Issue
Block a user