with the `help` command to explore and list all commands available. Enter will also try to see if the location to be entered is an existing Nu command, if it is it will let you inspect the command under `help`. This provides baseline needed so we can iterate on it.
51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::errors::ShellError;
|
|
use crate::parser::CommandRegistry;
|
|
use crate::prelude::*;
|
|
|
|
pub struct First;
|
|
|
|
impl WholeStreamCommand for First {
|
|
fn name(&self) -> &str {
|
|
"first"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("first")
|
|
.required("amount", SyntaxType::Literal)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Show only the first number of rows."
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
first(args, registry)
|
|
}
|
|
}
|
|
|
|
fn first(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
|
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.take(amount as u64),
|
|
))
|
|
}
|