nushell/src/commands/where_.rs

22 lines
655 B
Rust
Raw Normal View History

2019-05-16 02:42:44 +00:00
use crate::errors::ShellError;
use crate::object::base::find;
use crate::prelude::*;
pub fn r#where(args: CommandArgs) -> Result<OutputStream, ShellError> {
2019-05-22 07:12:03 +00:00
if args.args.is_empty() {
return Err(ShellError::string("select requires a field"));
}
2019-05-16 02:42:44 +00:00
2019-05-26 06:54:41 +00:00
let operation = args.args[0].as_operation()?;
let field = operation.left.as_string()?;
let operator = operation.operator;
let right = operation.right;
let input = args.input;
2019-05-16 02:42:44 +00:00
2019-05-26 06:54:41 +00:00
let objects = input
.filter(move |item| futures::future::ready(find(&item, &field, &operator, &right)))
.map(|item| ReturnValue::Value(item.copy()));
2019-05-16 02:42:44 +00:00
2019-05-26 06:54:41 +00:00
Ok(objects.boxed())
2019-05-16 02:42:44 +00:00
}