nushell/src/commands/reject.rs
Andrés N. Robalino ca0c6eaf58 This commit introduces a basic help feature. We can go to it
with the `help` command to explore and list all commands available.

Enter will also try to see if the location to be entered is an existing
Nu command, if it is it will let you inspect the command under `help`.

This provides baseline needed so we can iterate on it.
2019-08-31 19:06:11 -05:00

55 lines
1.3 KiB
Rust

use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::object::base::reject_fields;
use crate::prelude::*;
#[derive(Deserialize)]
pub struct RejectArgs {
rest: Vec<Tagged<String>>,
}
pub struct Reject;
impl WholeStreamCommand for Reject {
fn name(&self) -> &str {
"reject"
}
fn signature(&self) -> Signature {
Signature::build("reject").rest(SyntaxType::Member)
}
fn usage(&self) -> &str {
"Remove the given columns from the table."
}
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, reject)?.run()
}
}
fn reject(
RejectArgs { rest: fields }: RejectArgs,
RunnableContext { input, name, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
if fields.len() == 0 {
return Err(ShellError::labeled_error(
"Reject requires fields",
"needs parameter",
name,
));
}
let fields: Vec<_> = fields.iter().map(|f| f.item.clone()).collect();
let stream = input
.values
.map(move |item| reject_fields(&item, &fields, item.tag()).into_tagged_value());
Ok(stream.from_input_stream())
}