2019-05-15 18:14:51 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-05-22 07:12:03 +00:00
|
|
|
use crate::object::base::select_fields;
|
2019-05-15 22:58:44 +00:00
|
|
|
use crate::object::Value;
|
2019-05-15 18:14:51 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-06-02 18:53:30 +00:00
|
|
|
pub fn pick(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
2019-06-07 22:35:07 +00:00
|
|
|
if args.positional.len() == 0 {
|
2019-06-15 18:36:17 +00:00
|
|
|
return Err(ShellError::maybe_labeled_error(
|
|
|
|
"Pick requires fields",
|
|
|
|
"needs parameter",
|
|
|
|
args.name_span,
|
|
|
|
));
|
2019-05-22 07:12:03 +00:00
|
|
|
}
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-06-01 05:50:16 +00:00
|
|
|
let fields: Result<Vec<String>, _> = args.positional.iter().map(|a| a.as_string()).collect();
|
2019-05-22 07:12:03 +00:00
|
|
|
let fields = fields?;
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
let objects = args
|
|
|
|
.input
|
2019-05-23 07:23:06 +00:00
|
|
|
.map(move |item| Value::Object(select_fields(&item, &fields)))
|
|
|
|
.map(|item| ReturnValue::Value(item));
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-05-23 07:23:06 +00:00
|
|
|
let stream = Pin::new(Box::new(objects));
|
|
|
|
Ok(stream)
|
2019-05-15 18:14:51 +00:00
|
|
|
}
|