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 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-22 03:43:37 +00:00
|
|
|
if args.len() == 0 {
|
2019-06-15 18:36:17 +00:00
|
|
|
return Err(ShellError::maybe_labeled_error(
|
|
|
|
"Pick requires fields",
|
|
|
|
"needs parameter",
|
2019-07-20 02:27:10 +00:00
|
|
|
args.call_info.name_span,
|
2019-06-15 18:36:17 +00:00
|
|
|
));
|
2019-05-22 07:12:03 +00:00
|
|
|
}
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-06-22 03:43:37 +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-07-08 16:44:53 +00:00
|
|
|
let input = args.input;
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-07-08 16:44:53 +00:00
|
|
|
let objects = input
|
2019-07-03 20:31:15 +00:00
|
|
|
.values
|
2019-07-09 04:31:26 +00:00
|
|
|
.map(move |value| select_fields(&value.item, &fields, value.span));
|
2019-05-15 18:14:51 +00:00
|
|
|
|
2019-07-03 20:31:15 +00:00
|
|
|
Ok(objects.from_input_stream())
|
2019-05-15 18:14:51 +00:00
|
|
|
}
|