2019-05-16 04:42:44 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-07-08 18:44:53 +02:00
|
|
|
use crate::object::Block;
|
2019-05-16 04:42:44 +02:00
|
|
|
use crate::prelude::*;
|
2019-07-03 22:31:15 +02:00
|
|
|
use futures::future::ready;
|
|
|
|
use log::trace;
|
2019-05-16 04:42:44 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
command! {
|
2019-07-15 23:16:27 +02:00
|
|
|
Where as where(args, condition: Block,) {
|
2019-07-12 21:22:08 +02:00
|
|
|
let input: InputStream = trace_stream!(target: "nu::trace_stream::where", "where input" = args.input);
|
2019-05-28 08:45:18 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
input.values.filter_map(move |item| {
|
|
|
|
let result = condition.invoke(&item);
|
2019-05-28 08:45:18 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
let return_value = match result {
|
|
|
|
Err(err) => Some(Err(err)),
|
2019-07-08 18:44:53 +02:00
|
|
|
Ok(v) if v.is_true() => Some(Ok(ReturnSuccess::Value(item.clone()))),
|
2019-07-03 22:31:15 +02:00
|
|
|
_ => None,
|
|
|
|
};
|
2019-05-28 08:45:18 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
ready(return_value)
|
|
|
|
})
|
2019-05-22 09:12:03 +02:00
|
|
|
}
|
2019-05-16 04:42:44 +02:00
|
|
|
}
|