diff --git a/crates/nu-command/src/filters/last.rs b/crates/nu-command/src/filters/last.rs index b626369625..f9ed664feb 100644 --- a/crates/nu-command/src/filters/last.rs +++ b/crates/nu-command/src/filters/last.rs @@ -2,8 +2,9 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value}; -//use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value}; +use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value}; + +use std::convert::TryInto; #[derive(Clone)] pub struct Last; @@ -34,39 +35,42 @@ impl Command for Last { ) -> Result { let rows: Option = call.opt(engine_state, stack, 0)?; - let vlength = length(input)?; - dbg!(vlength); - - let end_rows_desired = if let Some(quantity) = rows { - quantity - } else { - 1 - }; - - let beginning_rows_to_skip = if end_rows_desired < vlength { - vlength - end_rows_desired - } else { - 0 - }; - - dbg!(beginning_rows_to_skip); - - // let iter = v.into_iter().skip(beginning_rows_to_skip); - - //dbg!(input.clone()); /* - match input { - PipelineData::Stream(stream) => Ok(stream.into_pipeline_data()), - PipelineData::Value(Value::List { vals, .. }) => { - Ok(vals.into_iter().into_pipeline_data()) - } - _ => { - dbg!("Fall to the bottom"); - Ok(PipelineData::Value(Value::Nothing { span: call.head })) - } - } + let vlength = length(input)?; + dbg!(vlength); + + let end_rows_desired = if let Some(quantity) = rows { + quantity + } else { + 1 + }; + + let beginning_rows_to_skip = if end_rows_desired < vlength { + vlength - end_rows_desired + } else { + 0 + }; + + dbg!(beginning_rows_to_skip); */ - Ok(PipelineData::Value(Value::Nothing { span: call.head })) + + let beginning_rows_to_skip = 2; + + match input { + PipelineData::Stream(stream) => Ok(stream + .skip(beginning_rows_to_skip.try_into().unwrap()) + .into_pipeline_data()), + PipelineData::Value(Value::List { vals, .. }) => Ok(vals + .into_iter() + .skip(beginning_rows_to_skip.try_into().unwrap()) + .into_pipeline_data()), + _ => { + dbg!("Fall to the bottom"); + Ok(PipelineData::Value(Value::Nothing { span: call.head })) + } + } + + // Ok(PipelineData::Value(Value::Nothing { span: call.head })) } }