Add support for real comparison operators

This commit is contained in:
Jonathan Turner
2019-05-17 18:27:31 -07:00
parent 52716d0c24
commit 76c295995d
3 changed files with 106 additions and 41 deletions

View File

@@ -15,16 +15,21 @@ impl crate::Command for Where {
let field: Result<String, _> = args.args[0].as_string();
let field = field?;
let op: Result<String, _> = args.args[1].as_string();
let op = op?;
match args.args[1] {
Value::Primitive(Primitive::Operator(ref operator)) => {
let objects = args
.input
.iter()
.filter(|item| find(&item, &field, operator, &args.args[2]))
.map(|item| ReturnValue::Value(item.copy()))
.collect();
let objects = args
.input
.iter()
.filter(|item| find(&item, &field, &op, &args.args[2]))
.map(|item| ReturnValue::Value(item.copy()))
.collect();
Ok(objects)
Ok(objects)
}
ref x => {
println!("{:?}", x);
Err(ShellError::string("expected a comparison operator"))
}
}
}
}