2019-07-23 22:22:11 +00:00
|
|
|
use crate::context::CommandRegistry;
|
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-07-23 22:22:11 +00: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 08:54:29 +00:00
|
|
|
return Err(ShellError::labeled_error(
|
2019-06-15 18:36:17 +00:00
|
|
|
"Pick requires fields",
|
|
|
|
"needs parameter",
|
2019-07-23 22:22:11 +00:00
|
|
|
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-07-23 22:22:11 +00:00
|
|
|
let fields: Result<Vec<String>, _> = args
|
|
|
|
.positional
|
|
|
|
.iter()
|
|
|
|
.flatten()
|
|
|
|
.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-07-08 16:44:53 +00:00
|
|
|
let objects = input
|
2019-07-03 20:31:15 +00:00
|
|
|
.values
|
2019-08-05 08:54:29 +00:00
|
|
|
.map(move |value| select_fields(&value.item, &fields, value.tag()));
|
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
|
|
|
}
|