From 3795c2a39d00f5f7b55224ba08ba2a808f4af43f Mon Sep 17 00:00:00 2001 From: Alex Shadley Date: Tue, 11 May 2021 20:59:08 -0500 Subject: [PATCH] Migrate last to engine-p (#3406) * migrates last to engine-p * removes unused import * linter fix * switch to as_usize() --- crates/nu-command/src/commands/last.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/nu-command/src/commands/last.rs b/crates/nu-command/src/commands/last.rs index a247f31e57..6538fc49b6 100644 --- a/crates/nu-command/src/commands/last.rs +++ b/crates/nu-command/src/commands/last.rs @@ -2,15 +2,9 @@ use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value}; -use nu_source::Tagged; pub struct Last; -#[derive(Deserialize)] -pub struct LastArgs { - rows: Option>, -} - impl WholeStreamCommand for Last { fn name(&self) -> &str { "last" @@ -28,7 +22,7 @@ impl WholeStreamCommand for Last { "Show only the last number of rows." } - fn run_with_actions(&self, args: CommandArgs) -> Result { + fn run(&self, args: CommandArgs) -> Result { last(args) } @@ -52,12 +46,13 @@ impl WholeStreamCommand for Last { } } -fn last(args: CommandArgs) -> Result { - let (LastArgs { rows }, input) = args.process()?; - let v: Vec<_> = input.into_vec(); +fn last(args: CommandArgs) -> Result { + let args = args.evaluate_once()?; + let rows = args.nth(0).cloned(); + let v: Vec<_> = args.input.into_vec(); let end_rows_desired = if let Some(quantity) = rows { - *quantity as usize + quantity.as_usize()? } else { 1 }; @@ -70,7 +65,7 @@ fn last(args: CommandArgs) -> Result { let iter = v.into_iter().skip(beginning_rows_to_skip); - Ok((iter).to_action_stream()) + Ok(OutputStream::from_stream(iter)) } #[cfg(test)]