Fix #4942, and add a table sorting example for sort-by command (#4948)

* Fix #4942, and add a table sorting example for `sort-by` command

* ci skip
This commit is contained in:
Justin Ma 2022-03-25 11:22:57 +08:00 committed by GitHub
parent 7c92791eed
commit b007290a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -351,7 +351,7 @@ ls | each {|x| $x.name}
```
The above will create a list of the filenames in the directory.
```
if true { echo "it's true" } { echo "it's not true" }
if true { echo "it's true" } else { echo "it's not true" }
```
This `if` call will run the first block if the expression is true, or the
second block if the expression is false.

View File

@ -97,6 +97,27 @@ impl Command for SortBy {
span: Span::test_data(),
}),
},
Example {
description: "Sort a table by its column (reversed order)",
example: "[[fruit count]; [apple 9] [pear 3] [orange 7]] | sort-by fruit -r",
result: Some(Value::List {
vals: vec![
Value::test_record(
vec!["fruit", "count"],
vec![Value::test_string("pear"), Value::test_int(3)],
),
Value::test_record(
vec!["fruit", "count"],
vec![Value::test_string("orange"), Value::test_int(7)],
),
Value::test_record(
vec!["fruit", "count"],
vec![Value::test_string("apple"), Value::test_int(9)],
),
],
span: Span::test_data(),
}),
},
]
}