mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
Migrate last to engine-p (#3406)
* migrates last to engine-p * removes unused import * linter fix * switch to as_usize()
This commit is contained in:
parent
311c0e3f50
commit
3795c2a39d
@ -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<Tagged<u64>>,
|
||||
}
|
||||
|
||||
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<ActionStream, ShellError> {
|
||||
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
last(args)
|
||||
}
|
||||
|
||||
@ -52,12 +46,13 @@ impl WholeStreamCommand for Last {
|
||||
}
|
||||
}
|
||||
|
||||
fn last(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
||||
let (LastArgs { rows }, input) = args.process()?;
|
||||
let v: Vec<_> = input.into_vec();
|
||||
fn last(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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<ActionStream, ShellError> {
|
||||
|
||||
let iter = v.into_iter().skip(beginning_rows_to_skip);
|
||||
|
||||
Ok((iter).to_action_stream())
|
||||
Ok(OutputStream::from_stream(iter))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user