use crate::commands::WholeStreamCommand; use crate::errors::ShellError; use crate::parser::CommandRegistry; use crate::prelude::*; pub struct Nth; impl WholeStreamCommand for Nth { fn run( &self, args: CommandArgs, registry: &CommandRegistry, ) -> Result { nth(args, registry) } fn name(&self) -> &str { "nth" } fn signature(&self) -> Signature { Signature::build("nth").required("amount", SyntaxType::Literal) } } fn nth(args: CommandArgs, registry: &CommandRegistry) -> Result { let args = args.evaluate_once(registry)?; let amount = args.expect_nth(0)?.as_i64(); let amount = match amount { Ok(o) => o, Err(_) => { return Err(ShellError::labeled_error( "Value is not a number", "expected integer", args.expect_nth(0)?.span(), )) } }; Ok(OutputStream::from_input( args.input.values.skip(amount as u64).take(1), )) }