From 9baf72015630750c296e5a0cb089f9a81da861c5 Mon Sep 17 00:00:00 2001 From: Michael Angerman Date: Wed, 27 Oct 2021 08:07:37 -0700 Subject: [PATCH] add in an example --- crates/nu-command/src/filters/last.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filters/last.rs b/crates/nu-command/src/filters/last.rs index 77cad9604c..57223981f7 100644 --- a/crates/nu-command/src/filters/last.rs +++ b/crates/nu-command/src/filters/last.rs @@ -2,7 +2,9 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape}; +use nu_protocol::{ + Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, +}; use std::convert::TryInto; #[derive(Clone)] @@ -25,6 +27,17 @@ impl Command for Last { "Show only the last number of rows." } + fn examples(&self) -> Vec { + vec![Example { + example: "[1,2,3] | last 2", + description: "Get the last 2 items", + result: Some(Value::List { + vals: vec![Value::test_int(2), Value::test_int(3)], + span: Span::unknown(), + }), + }] + } + fn run( &self, engine_state: &EngineState, @@ -58,3 +71,15 @@ fn rows_to_skip(count: i64, rows: Option) -> i64 { return 0; }; } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_examples() { + use crate::test_examples; + + test_examples(Last {}) + } +}