2019-08-19 07:16:39 +02:00
|
|
|
use crate::commands::WholeStreamCommand;
|
2019-08-12 07:13:58 +02:00
|
|
|
use crate::errors::ShellError;
|
|
|
|
use crate::parser::CommandRegistry;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-08-20 05:12:31 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct NthArgs {
|
2019-08-20 08:11:11 +02:00
|
|
|
amount: Tagged<i64>,
|
2019-08-20 05:12:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 07:16:39 +02:00
|
|
|
pub struct Nth;
|
|
|
|
|
|
|
|
impl WholeStreamCommand for Nth {
|
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-08-20 05:12:31 +02:00
|
|
|
args.process(registry, nth)?.run()
|
2019-08-19 07:16:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
"nth"
|
|
|
|
}
|
2019-08-12 07:13:58 +02:00
|
|
|
|
2019-08-19 07:16:39 +02:00
|
|
|
fn signature(&self) -> Signature {
|
2019-08-20 08:11:11 +02:00
|
|
|
Signature::build("nth").required("amount", SyntaxType::Any)
|
2019-08-12 07:13:58 +02:00
|
|
|
}
|
2019-08-19 07:16:39 +02:00
|
|
|
}
|
|
|
|
|
2019-08-20 05:12:31 +02:00
|
|
|
fn nth(
|
2019-08-20 08:11:11 +02:00
|
|
|
NthArgs { amount }: NthArgs,
|
2019-08-20 05:12:31 +02:00
|
|
|
RunnableContext { input, .. }: RunnableContext,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-08-12 07:13:58 +02:00
|
|
|
Ok(OutputStream::from_input(
|
2019-08-20 05:12:31 +02:00
|
|
|
input.values.skip(amount.item as u64).take(1),
|
2019-08-12 07:13:58 +02:00
|
|
|
))
|
|
|
|
}
|