forked from extern/nushell
@ -11,7 +11,6 @@ pub struct Arguments {
|
||||
rows: Option<Tagged<usize>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"keep"
|
||||
@ -29,8 +28,8 @@ impl WholeStreamCommand for Command {
|
||||
"Keep the number of rows only."
|
||||
}
|
||||
|
||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
keep(args).await
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
keep(args)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
@ -54,8 +53,8 @@ impl WholeStreamCommand for Command {
|
||||
}
|
||||
}
|
||||
|
||||
async fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (Arguments { rows }, input) = args.process().await?;
|
||||
fn keep(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let (Arguments { rows }, input) = args.process()?;
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
*quantity
|
||||
} else {
|
||||
|
@ -8,7 +8,6 @@ use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
||||
|
||||
pub struct SubCommand;
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"keep until"
|
||||
@ -28,10 +27,10 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Keeps rows until the condition matches."
|
||||
}
|
||||
|
||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||
|
||||
let call_info = args.evaluate_once().await?;
|
||||
let call_info = args.evaluate_once()?;
|
||||
|
||||
let block = call_info.args.expect_nth(0)?.clone();
|
||||
|
||||
@ -88,13 +87,11 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctx.scope.add_var("$it", item.clone());
|
||||
trace!("ITEM = {:?}", item);
|
||||
|
||||
async move {
|
||||
let result = evaluate_baseline_expr(&*condition, &*ctx).await;
|
||||
ctx.scope.exit_scope();
|
||||
trace!("RESULT = {:?}", result);
|
||||
let result = evaluate_baseline_expr(&*condition, &*ctx);
|
||||
ctx.scope.exit_scope();
|
||||
trace!("RESULT = {:?}", result);
|
||||
|
||||
!matches!(result, Ok(ref v) if v.is_true())
|
||||
}
|
||||
!matches!(result, Ok(ref v) if v.is_true())
|
||||
})
|
||||
.to_output_stream())
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue,
|
||||
|
||||
pub struct SubCommand;
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"keep while"
|
||||
@ -27,9 +26,9 @@ impl WholeStreamCommand for SubCommand {
|
||||
"Keeps rows while the condition matches."
|
||||
}
|
||||
|
||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let ctx = Arc::new(EvaluationContext::from_args(&args));
|
||||
let call_info = args.evaluate_once().await?;
|
||||
let call_info = args.evaluate_once()?;
|
||||
|
||||
let block = call_info.args.expect_nth(0)?.clone();
|
||||
|
||||
@ -87,13 +86,11 @@ impl WholeStreamCommand for SubCommand {
|
||||
ctx.scope.add_vars(&captured.entries);
|
||||
trace!("ITEM = {:?}", item);
|
||||
|
||||
async move {
|
||||
let result = evaluate_baseline_expr(&*condition, &*ctx).await;
|
||||
ctx.scope.exit_scope();
|
||||
trace!("RESULT = {:?}", result);
|
||||
let result = evaluate_baseline_expr(&*condition, &*ctx);
|
||||
ctx.scope.exit_scope();
|
||||
trace!("RESULT = {:?}", result);
|
||||
|
||||
matches!(result, Ok(ref v) if v.is_true())
|
||||
}
|
||||
matches!(result, Ok(ref v) if v.is_true())
|
||||
})
|
||||
.to_output_stream())
|
||||
}
|
||||
|
Reference in New Issue
Block a user