2019-07-24 00:22:11 +02:00
|
|
|
use crate::context::CommandRegistry;
|
2019-05-15 20:14:51 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-05-22 09:12:03 +02:00
|
|
|
use crate::object::base::select_fields;
|
2019-05-15 20:14:51 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
pub fn pick(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
|
|
let args = args.evaluate_once(registry)?;
|
|
|
|
let len = args.len();
|
|
|
|
let span = args.name_span();
|
|
|
|
let (input, args) = args.parts();
|
|
|
|
|
|
|
|
if len == 0 {
|
2019-08-05 10:54:29 +02:00
|
|
|
return Err(ShellError::labeled_error(
|
2019-06-15 20:36:17 +02:00
|
|
|
"Pick requires fields",
|
|
|
|
"needs parameter",
|
2019-07-24 00:22:11 +02:00
|
|
|
span,
|
2019-06-15 20:36:17 +02:00
|
|
|
));
|
2019-05-22 09:12:03 +02:00
|
|
|
}
|
2019-05-15 20:14:51 +02:00
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
let fields: Result<Vec<String>, _> = args
|
|
|
|
.positional
|
|
|
|
.iter()
|
|
|
|
.flatten()
|
|
|
|
.map(|a| a.as_string())
|
|
|
|
.collect();
|
|
|
|
|
2019-05-22 09:12:03 +02:00
|
|
|
let fields = fields?;
|
2019-05-15 20:14:51 +02:00
|
|
|
|
2019-07-08 18:44:53 +02:00
|
|
|
let objects = input
|
2019-07-03 22:31:15 +02:00
|
|
|
.values
|
2019-08-05 10:54:29 +02:00
|
|
|
.map(move |value| select_fields(&value.item, &fields, value.tag()));
|
2019-05-15 20:14:51 +02:00
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
Ok(objects.from_input_stream())
|
2019-05-15 20:14:51 +02:00
|
|
|
}
|