forked from extern/nushell
Merge skip command varieties into one command with sub commands. (#2179)
This commit is contained in:
committed by
GitHub
parent
5f1075544c
commit
71e55541d7
@ -105,8 +105,6 @@ pub(crate) mod shells;
|
||||
pub(crate) mod shuffle;
|
||||
pub(crate) mod size;
|
||||
pub(crate) mod skip;
|
||||
pub(crate) mod skip_until;
|
||||
pub(crate) mod skip_while;
|
||||
pub(crate) mod sort_by;
|
||||
pub(crate) mod split;
|
||||
pub(crate) mod split_by;
|
||||
@ -245,9 +243,7 @@ pub(crate) use select::Select;
|
||||
pub(crate) use shells::Shells;
|
||||
pub(crate) use shuffle::Shuffle;
|
||||
pub(crate) use size::Size;
|
||||
pub(crate) use skip::Skip;
|
||||
pub(crate) use skip_until::SkipUntil;
|
||||
pub(crate) use skip_while::SkipWhile;
|
||||
pub(crate) use skip::{Skip, SkipUntil, SkipWhile};
|
||||
pub(crate) use sort_by::SortBy;
|
||||
pub(crate) use split::{Split, SplitChars, SplitColumn, SplitRow};
|
||||
pub(crate) use split_by::SplitBy;
|
||||
|
@ -5,21 +5,21 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, SyntaxShape, UntaggedValue};
|
||||
use nu_source::Tagged;
|
||||
|
||||
pub struct Skip;
|
||||
pub struct Command;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SkipArgs {
|
||||
pub struct Arguments {
|
||||
rows: Option<Tagged<usize>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for Skip {
|
||||
impl WholeStreamCommand for Command {
|
||||
fn name(&self) -> &str {
|
||||
"skip"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("skip").optional("rows", SyntaxShape::Int, "how many rows to skip")
|
||||
Signature::build("skip").optional("rows", SyntaxShape::Int, "How many rows to skip")
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
@ -48,7 +48,7 @@ impl WholeStreamCommand for Skip {
|
||||
|
||||
async fn skip(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
let registry = registry.clone();
|
||||
let (SkipArgs { rows }, input) = args.process(®istry).await?;
|
||||
let (Arguments { rows }, input) = args.process(®istry).await?;
|
||||
let rows_desired = if let Some(quantity) = rows {
|
||||
*quantity
|
||||
} else {
|
||||
@ -60,12 +60,12 @@ async fn skip(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStr
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Skip;
|
||||
use super::Command;
|
||||
|
||||
#[test]
|
||||
fn examples_work_as_expected() {
|
||||
use crate::examples::test as test_examples;
|
||||
|
||||
test_examples(Skip {})
|
||||
test_examples(Command {})
|
||||
}
|
||||
}
|
7
crates/nu-cli/src/commands/skip/mod.rs
Normal file
7
crates/nu-cli/src/commands/skip/mod.rs
Normal file
@ -0,0 +1,7 @@
|
||||
mod command;
|
||||
mod until;
|
||||
mod while_;
|
||||
|
||||
pub use command::Command as Skip;
|
||||
pub use until::SubCommand as SkipUntil;
|
||||
pub use while_::SubCommand as SkipWhile;
|
@ -5,20 +5,20 @@ use log::trace;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
|
||||
pub struct SkipUntil;
|
||||
pub struct SubCommand;
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for SkipUntil {
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"skip-until"
|
||||
"skip until"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("skip-until")
|
||||
Signature::build("skip until")
|
||||
.required(
|
||||
"condition",
|
||||
SyntaxShape::Math,
|
||||
"the condition that must be met to stop skipping",
|
||||
"The condition that must be met to stop skipping",
|
||||
)
|
||||
.filter()
|
||||
}
|
||||
@ -108,12 +108,12 @@ impl WholeStreamCommand for SkipUntil {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SkipUntil;
|
||||
use super::SubCommand;
|
||||
|
||||
#[test]
|
||||
fn examples_work_as_expected() {
|
||||
use crate::examples::test as test_examples;
|
||||
|
||||
test_examples(SkipUntil {})
|
||||
test_examples(SubCommand {})
|
||||
}
|
||||
}
|
@ -5,20 +5,20 @@ use log::trace;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
|
||||
pub struct SkipWhile;
|
||||
pub struct SubCommand;
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for SkipWhile {
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"skip-while"
|
||||
"skip while"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("skip-while")
|
||||
Signature::build("skip while")
|
||||
.required(
|
||||
"condition",
|
||||
SyntaxShape::Math,
|
||||
"the condition that must be met to continue skipping",
|
||||
"The condition that must be met to continue skipping",
|
||||
)
|
||||
.filter()
|
||||
}
|
||||
@ -108,12 +108,12 @@ impl WholeStreamCommand for SkipWhile {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SkipWhile;
|
||||
use super::SubCommand;
|
||||
|
||||
#[test]
|
||||
fn examples_work_as_expected() {
|
||||
use crate::examples::test as test_examples;
|
||||
|
||||
test_examples(SkipWhile {})
|
||||
test_examples(SubCommand {})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user