nushell/src/commands/skip_while.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

53 lines
1.2 KiB
Rust

use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::prelude::*;
pub struct SkipWhile;
#[derive(Deserialize)]
pub struct SkipWhileArgs {
condition: value::Block,
}
impl WholeStreamCommand for SkipWhile {
fn name(&self) -> &str {
"skip-while"
}
fn signature(&self) -> Signature {
Signature::build("skip-while")
.required("condition", SyntaxType::Block)
.filter()
}
fn usage(&self) -> &str {
"Skips rows while the condition matches."
}
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
args.process(registry, skip_while)?.run()
}
}
pub fn skip_while(
SkipWhileArgs { condition }: SkipWhileArgs,
RunnableContext { input, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> {
let objects = input.values.skip_while(move |item| {
let result = condition.invoke(&item);
let return_value = match result {
Ok(ref v) if v.is_true() => true,
_ => false,
};
futures::future::ready(return_value)
});
Ok(objects.from_input_stream())
}