mirror of
https://github.com/nushell/nushell.git
synced 2024-11-23 00:43:33 +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_engine::WholeStreamCommand;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
use nu_source::Tagged;
|
|
||||||
|
|
||||||
pub struct Last;
|
pub struct Last;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct LastArgs {
|
|
||||||
rows: Option<Tagged<u64>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WholeStreamCommand for Last {
|
impl WholeStreamCommand for Last {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"last"
|
"last"
|
||||||
@ -28,7 +22,7 @@ impl WholeStreamCommand for Last {
|
|||||||
"Show only the last number of rows."
|
"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)
|
last(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,12 +46,13 @@ impl WholeStreamCommand for Last {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
fn last(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let (LastArgs { rows }, input) = args.process()?;
|
let args = args.evaluate_once()?;
|
||||||
let v: Vec<_> = input.into_vec();
|
let rows = args.nth(0).cloned();
|
||||||
|
let v: Vec<_> = args.input.into_vec();
|
||||||
|
|
||||||
let end_rows_desired = if let Some(quantity) = rows {
|
let end_rows_desired = if let Some(quantity) = rows {
|
||||||
*quantity as usize
|
quantity.as_usize()?
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
};
|
};
|
||||||
@ -70,7 +65,7 @@ fn last(args: CommandArgs) -> Result<ActionStream, ShellError> {
|
|||||||
|
|
||||||
let iter = v.into_iter().skip(beginning_rows_to_skip);
|
let iter = v.into_iter().skip(beginning_rows_to_skip);
|
||||||
|
|
||||||
Ok((iter).to_action_stream())
|
Ok(OutputStream::from_stream(iter))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user