mirror of
https://github.com/nushell/nushell
synced 2025-01-10 12:19:14 +00:00
b2c5af457e
This improves incremental build time when working on what was previously the root package. For example, previously all plugins would be rebuilt with a change to `src/commands/classified/external.rs`, but now only `nu-cli` will have to be rebuilt (and anything that depends on it).
56 lines
1.3 KiB
Rust
56 lines
1.3 KiB
Rust
use crate::commands::WholeStreamCommand;
|
|
use crate::context::CommandRegistry;
|
|
use crate::deserializer::NumericRange;
|
|
use crate::prelude::*;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{Signature, SyntaxShape};
|
|
use nu_source::Tagged;
|
|
|
|
#[derive(Deserialize)]
|
|
struct RangeArgs {
|
|
area: Tagged<NumericRange>,
|
|
}
|
|
|
|
pub struct Range;
|
|
|
|
impl WholeStreamCommand for Range {
|
|
fn name(&self) -> &str {
|
|
"range"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("range").required(
|
|
"rows ",
|
|
SyntaxShape::Range,
|
|
"range of rows to return: Eg) 4..7 (=> from 4 to 7)",
|
|
)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Return only the selected rows"
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
args: CommandArgs,
|
|
registry: &CommandRegistry,
|
|
) -> Result<OutputStream, ShellError> {
|
|
args.process(registry, range)?.run()
|
|
}
|
|
}
|
|
|
|
fn range(
|
|
RangeArgs { area }: RangeArgs,
|
|
RunnableContext { input, .. }: RunnableContext,
|
|
) -> Result<OutputStream, ShellError> {
|
|
let range = area.item;
|
|
let (from, _) = range.from;
|
|
let (to, _) = range.to;
|
|
|
|
let from = *from as usize;
|
|
let to = *to as usize;
|
|
|
|
Ok(OutputStream::from_input(
|
|
input.values.skip(from).take(to - from + 1),
|
|
))
|
|
}
|