Add suport for Filesize and Date for sort-by command (#855)

This commit is contained in:
Stefan Stanciulescu 2022-01-26 22:54:31 +01:00 committed by GitHub
parent 78b5da8255
commit e8b8836977
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
use chrono::{DateTime, FixedOffset};
use nu_engine::column::column_does_not_exist; use nu_engine::column::column_does_not_exist;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
@ -157,6 +158,8 @@ pub enum CompareValues {
// Floats(f64, f64), // Floats(f64, f64),
String(String, String), String(String, String),
Booleans(bool, bool), Booleans(bool, bool),
Filesize(i64, i64),
Date(DateTime<FixedOffset>, DateTime<FixedOffset>),
} }
impl CompareValues { impl CompareValues {
@ -167,6 +170,8 @@ impl CompareValues {
// CompareValues::Floats(left, right) => left.cmp(right), // CompareValues::Floats(left, right) => left.cmp(right),
CompareValues::String(left, right) => left.cmp(right), CompareValues::String(left, right) => left.cmp(right),
CompareValues::Booleans(left, right) => left.cmp(right), CompareValues::Booleans(left, right) => left.cmp(right),
CompareValues::Filesize(left, right) => left.cmp(right),
CompareValues::Date(left, right) => left.cmp(right),
} }
} }
} }
@ -176,11 +181,17 @@ pub fn coerce_compare(
right: &Value, right: &Value,
) -> Result<CompareValues, (&'static str, &'static str)> { ) -> Result<CompareValues, (&'static str, &'static str)> {
match (left, right) { match (left, right) {
/* // (Value::Float { val: left, .. }, Value::Float { val: right, .. }) => {
(Value::Float { val: left, .. }, Value::Float { val: right, .. }) => { // Ok(CompareValues::Floats(*left, *right))
Ok(CompareValues::Floats(*left, *right)) // }
(Value::Filesize { val: left, .. }, Value::Filesize { val: right, .. }) => {
Ok(CompareValues::Filesize(*left, *right))
} }
*/
(Value::Date { val: left, .. }, Value::Date { val: right, .. }) => {
Ok(CompareValues::Date(*left, *right))
}
(Value::Int { val: left, .. }, Value::Int { val: right, .. }) => { (Value::Int { val: left, .. }, Value::Int { val: right, .. }) => {
Ok(CompareValues::Ints(*left, *right)) Ok(CompareValues::Ints(*left, *right))
} }