2019-08-19 07:16:39 +02:00
|
|
|
use crate::commands::WholeStreamCommand;
|
2019-05-15 18:12:38 +02:00
|
|
|
use crate::errors::ShellError;
|
2019-07-24 00:22:11 +02:00
|
|
|
use crate::parser::CommandRegistry;
|
2019-05-15 18:12:38 +02:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2019-08-19 07:16:39 +02:00
|
|
|
pub struct First;
|
|
|
|
|
2019-09-01 18:20:31 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct FirstArgs {
|
|
|
|
amount: Tagged<u64>,
|
|
|
|
}
|
|
|
|
|
2019-08-19 07:16:39 +02:00
|
|
|
impl WholeStreamCommand for First {
|
2019-08-30 00:52:32 +02:00
|
|
|
fn name(&self) -> &str {
|
|
|
|
"first"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn signature(&self) -> Signature {
|
2019-09-11 16:36:50 +02:00
|
|
|
Signature::build("first").required("amount", SyntaxType::Literal)
|
2019-08-30 00:52:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn usage(&self) -> &str {
|
|
|
|
"Show only the first number of rows."
|
|
|
|
}
|
|
|
|
|
2019-08-19 07:16:39 +02:00
|
|
|
fn run(
|
|
|
|
&self,
|
|
|
|
args: CommandArgs,
|
|
|
|
registry: &CommandRegistry,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
2019-09-01 18:20:31 +02:00
|
|
|
args.process(registry, first)?.run()
|
2019-08-19 07:16:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 18:20:31 +02:00
|
|
|
fn first(
|
|
|
|
FirstArgs { amount }: FirstArgs,
|
|
|
|
context: RunnableContext,
|
|
|
|
) -> Result<OutputStream, ShellError> {
|
|
|
|
Ok(OutputStream::from_input(context.input.values.take(*amount)))
|
2019-05-15 18:12:38 +02:00
|
|
|
}
|