forked from extern/nushell
commit
e0640d7791
@ -155,6 +155,7 @@ Nu adheres closely to a set of goals that make up its design philosophy. As feat
|
|||||||
| edit field value | Edit an existing field to have a new value |
|
| edit field value | Edit an existing field to have a new value |
|
||||||
| skip amount | Skip a number of rows |
|
| skip amount | Skip a number of rows |
|
||||||
| first amount | Show only the first number of rows |
|
| first amount | Show only the first number of rows |
|
||||||
|
| nth row-number | Return only the selected row |
|
||||||
| str (field) | Apply string function. Optional use the field of a table |
|
| str (field) | Apply string function. Optional use the field of a table |
|
||||||
| tags | Read the tags (metadata) for values |
|
| tags | Read the tags (metadata) for values |
|
||||||
| to-array | Collapse rows into a single list |
|
| to-array | Collapse rows into a single list |
|
||||||
|
@ -158,6 +158,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
|||||||
command("size", Box::new(size::size)),
|
command("size", Box::new(size::size)),
|
||||||
command("from-yaml", Box::new(from_yaml::from_yaml)),
|
command("from-yaml", Box::new(from_yaml::from_yaml)),
|
||||||
command("enter", Box::new(enter::enter)),
|
command("enter", Box::new(enter::enter)),
|
||||||
|
command("nth", Box::new(nth::nth)),
|
||||||
command("n", Box::new(next::next)),
|
command("n", Box::new(next::next)),
|
||||||
command("p", Box::new(prev::prev)),
|
command("p", Box::new(prev::prev)),
|
||||||
command("lines", Box::new(lines::lines)),
|
command("lines", Box::new(lines::lines)),
|
||||||
|
@ -24,6 +24,7 @@ crate mod lines;
|
|||||||
crate mod ls;
|
crate mod ls;
|
||||||
crate mod mkdir;
|
crate mod mkdir;
|
||||||
crate mod next;
|
crate mod next;
|
||||||
|
crate mod nth;
|
||||||
crate mod open;
|
crate mod open;
|
||||||
crate mod pick;
|
crate mod pick;
|
||||||
crate mod plugin;
|
crate mod plugin;
|
||||||
|
@ -2,8 +2,6 @@ use crate::errors::ShellError;
|
|||||||
use crate::parser::CommandRegistry;
|
use crate::parser::CommandRegistry;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
// TODO: "Amount remaining" wrapper
|
|
||||||
|
|
||||||
pub fn first(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
pub fn first(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||||
let args = args.evaluate_once(registry)?;
|
let args = args.evaluate_once(registry)?;
|
||||||
|
|
||||||
|
32
src/commands/nth.rs
Normal file
32
src/commands/nth.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use crate::errors::ShellError;
|
||||||
|
use crate::parser::CommandRegistry;
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
pub fn nth(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||||
|
let args = args.evaluate_once(registry)?;
|
||||||
|
|
||||||
|
if args.len() == 0 {
|
||||||
|
return Err(ShellError::labeled_error(
|
||||||
|
"Nth requires an amount",
|
||||||
|
"needs amount",
|
||||||
|
args.name_span(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
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),
|
||||||
|
))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user