mirror of
https://github.com/nushell/nushell.git
synced 2025-01-03 21:09:52 +01:00
Merge skip command varieties into one command with sub commands. (#2179)
This commit is contained in:
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 {})
|
||||
}
|
||||
}
|
@ -37,7 +37,7 @@ fn condition_is_met() {
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip-while "Chicken Collection" != "Blue Chickens"
|
||||
| skip while "Chicken Collection" != "Blue Chickens"
|
||||
| keep-until "Chicken Collection" == "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
|
@ -7,7 +7,7 @@ fn lines() {
|
||||
r#"
|
||||
open cargo_sample.toml -r
|
||||
| lines
|
||||
| skip-while $it != "[dependencies]"
|
||||
| skip while $it != "[dependencies]"
|
||||
| skip 1
|
||||
| first 1
|
||||
| split column "="
|
||||
|
@ -43,8 +43,7 @@ mod rm;
|
||||
mod save;
|
||||
mod select;
|
||||
mod semicolon;
|
||||
mod skip_until;
|
||||
mod skip_while;
|
||||
mod skip;
|
||||
mod sort_by;
|
||||
mod split_by;
|
||||
mod split_column;
|
||||
|
2
crates/nu-cli/tests/commands/skip/mod.rs
Normal file
2
crates/nu-cli/tests/commands/skip/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
mod until;
|
||||
mod while_;
|
@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip-while_test_1", |dirs, sandbox| {
|
||||
Playground::setup("skip_until_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
@ -37,7 +37,7 @@ fn condition_is_met() {
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip-while "Chicken Collection" != "Red Chickens"
|
||||
| skip until "Chicken Collection" == "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn condition_is_met() {
|
||||
Playground::setup("skip-until_test_1", |dirs, sandbox| {
|
||||
Playground::setup("skip_while_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"caballeros.txt",
|
||||
r#"
|
||||
@ -37,7 +37,7 @@ fn condition_is_met() {
|
||||
| skip 2
|
||||
| split column ','
|
||||
| headers
|
||||
| skip-until "Chicken Collection" == "Red Chickens"
|
||||
| skip while "Chicken Collection" != "Red Chickens"
|
||||
| skip 1
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
Loading…
Reference in New Issue
Block a user