diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 73d69cdd2f..05bca9b104 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -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; diff --git a/crates/nu-cli/src/commands/skip.rs b/crates/nu-cli/src/commands/skip/command.rs similarity index 85% rename from crates/nu-cli/src/commands/skip.rs rename to crates/nu-cli/src/commands/skip/command.rs index 2008f60d83..9450d8d0bf 100644 --- a/crates/nu-cli/src/commands/skip.rs +++ b/crates/nu-cli/src/commands/skip/command.rs @@ -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>, } #[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 { 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 &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 {}) } } diff --git a/crates/nu-cli/src/commands/skip_while.rs b/crates/nu-cli/src/commands/skip/while_.rs similarity index 93% rename from crates/nu-cli/src/commands/skip_while.rs rename to crates/nu-cli/src/commands/skip/while_.rs index 19f9d73ed6..57ee93562a 100644 --- a/crates/nu-cli/src/commands/skip_while.rs +++ b/crates/nu-cli/src/commands/skip/while_.rs @@ -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 {}) } } diff --git a/crates/nu-cli/tests/commands/keep_until.rs b/crates/nu-cli/tests/commands/keep_until.rs index bc09099ec4..8df548d5e9 100644 --- a/crates/nu-cli/tests/commands/keep_until.rs +++ b/crates/nu-cli/tests/commands/keep_until.rs @@ -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" diff --git a/crates/nu-cli/tests/commands/lines.rs b/crates/nu-cli/tests/commands/lines.rs index 796bc8464e..db165bc56d 100644 --- a/crates/nu-cli/tests/commands/lines.rs +++ b/crates/nu-cli/tests/commands/lines.rs @@ -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 "=" diff --git a/crates/nu-cli/tests/commands/mod.rs b/crates/nu-cli/tests/commands/mod.rs index 4996f054f8..208d910b0a 100644 --- a/crates/nu-cli/tests/commands/mod.rs +++ b/crates/nu-cli/tests/commands/mod.rs @@ -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; diff --git a/crates/nu-cli/tests/commands/skip/mod.rs b/crates/nu-cli/tests/commands/skip/mod.rs new file mode 100644 index 0000000000..aa35de0702 --- /dev/null +++ b/crates/nu-cli/tests/commands/skip/mod.rs @@ -0,0 +1,2 @@ +mod until; +mod while_; diff --git a/crates/nu-cli/tests/commands/skip_while.rs b/crates/nu-cli/tests/commands/skip/until.rs similarity index 92% rename from crates/nu-cli/tests/commands/skip_while.rs rename to crates/nu-cli/tests/commands/skip/until.rs index 4e5d17f9ca..75330e925b 100644 --- a/crates/nu-cli/tests/commands/skip_while.rs +++ b/crates/nu-cli/tests/commands/skip/until.rs @@ -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" diff --git a/crates/nu-cli/tests/commands/skip_until.rs b/crates/nu-cli/tests/commands/skip/while_.rs similarity index 92% rename from crates/nu-cli/tests/commands/skip_until.rs rename to crates/nu-cli/tests/commands/skip/while_.rs index bd3da95a3a..9ac1809956 100644 --- a/crates/nu-cli/tests/commands/skip_until.rs +++ b/crates/nu-cli/tests/commands/skip/while_.rs @@ -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"