From 4f974efeba6fee79a16be1fbd169aef1ae7dc7c7 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Fri, 8 Apr 2022 08:49:28 +1200 Subject: [PATCH] Move 'keep' to 'take' (#5123) --- crates/nu-command/src/default_context.rs | 6 ++--- crates/nu-command/src/filters/keep/mod.rs | 7 ------ crates/nu-command/src/filters/mod.rs | 4 ++-- crates/nu-command/src/filters/take/mod.rs | 7 ++++++ .../filters/{keep/keep_.rs => take/take_.rs} | 22 +++++++++---------- .../keep_until.rs => take/take_until.rs} | 18 +++++++-------- .../keep_while.rs => take/take_while.rs} | 18 +++++++-------- crates/nu-command/tests/commands/mod.rs | 2 +- .../tests/commands/{keep => take}/mod.rs | 0 .../tests/commands/{keep => take}/rows.rs | 4 ++-- .../tests/commands/{keep => take}/until.rs | 4 ++-- .../tests/commands/{keep => take}/while_.rs | 4 ++-- 12 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 crates/nu-command/src/filters/keep/mod.rs create mode 100644 crates/nu-command/src/filters/take/mod.rs rename crates/nu-command/src/filters/{keep/keep_.rs => take/take_.rs} (88%) rename crates/nu-command/src/filters/{keep/keep_until.rs => take/take_until.rs} (85%) rename crates/nu-command/src/filters/{keep/keep_while.rs => take/take_while.rs} (85%) rename crates/nu-command/tests/commands/{keep => take}/mod.rs (100%) rename crates/nu-command/tests/commands/{keep => take}/rows.rs (89%) rename crates/nu-command/tests/commands/{keep => take}/until.rs (92%) rename crates/nu-command/tests/commands/{keep => take}/while_.rs (92%) diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 48326d885c..bc3866ca3a 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -80,11 +80,11 @@ pub fn create_default_context(cwd: impl AsRef) -> EngineState { Headers, Insert, SplitBy, - Keep, + Take, Merge, Move, - KeepUntil, - KeepWhile, + TakeWhile, + TakeUntil, Last, Length, Lines, diff --git a/crates/nu-command/src/filters/keep/mod.rs b/crates/nu-command/src/filters/keep/mod.rs deleted file mode 100644 index 8eaddb54f7..0000000000 --- a/crates/nu-command/src/filters/keep/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod keep_; -mod keep_until; -mod keep_while; - -pub use keep_::Keep; -pub use keep_until::KeepUntil; -pub use keep_while::KeepWhile; diff --git a/crates/nu-command/src/filters/mod.rs b/crates/nu-command/src/filters/mod.rs index ac4937ee18..4cf590f9e1 100644 --- a/crates/nu-command/src/filters/mod.rs +++ b/crates/nu-command/src/filters/mod.rs @@ -17,7 +17,6 @@ mod group; mod group_by; mod headers; mod insert; -mod keep; mod last; mod length; mod lines; @@ -38,6 +37,7 @@ mod skip; mod sort; mod sort_by; mod split_by; +mod take; mod transpose; mod uniq; mod update; @@ -67,7 +67,6 @@ pub use group::Group; pub use group_by::GroupBy; pub use headers::Headers; pub use insert::Insert; -pub use keep::*; pub use last::Last; pub use length::Length; pub use lines::Lines; @@ -88,6 +87,7 @@ pub use skip::*; pub use sort::Sort; pub use sort_by::SortBy; pub use split_by::SplitBy; +pub use take::*; pub use transpose::Transpose; pub use uniq::*; pub use update::Update; diff --git a/crates/nu-command/src/filters/take/mod.rs b/crates/nu-command/src/filters/take/mod.rs new file mode 100644 index 0000000000..19efe6c222 --- /dev/null +++ b/crates/nu-command/src/filters/take/mod.rs @@ -0,0 +1,7 @@ +mod take_; +mod take_until; +mod take_while; + +pub use take_::Take; +pub use take_until::TakeUntil; +pub use take_while::TakeWhile; diff --git a/crates/nu-command/src/filters/keep/keep_.rs b/crates/nu-command/src/filters/take/take_.rs similarity index 88% rename from crates/nu-command/src/filters/keep/keep_.rs rename to crates/nu-command/src/filters/take/take_.rs index 257833e6ba..64f76e53e2 100644 --- a/crates/nu-command/src/filters/keep/keep_.rs +++ b/crates/nu-command/src/filters/take/take_.rs @@ -9,28 +9,28 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct Keep; +pub struct Take; -impl Command for Keep { +impl Command for Take { fn name(&self) -> &str { - "keep" + "take" } fn signature(&self) -> Signature { Signature::build(self.name()) - .optional("n", SyntaxShape::Int, "the number of elements to keep") + .optional("n", SyntaxShape::Int, "the number of elements to take") .category(Category::Filters) } fn usage(&self) -> &str { - "Keep the first n elements of the input." + "Take the first n elements of the input." } fn examples(&self) -> Vec { vec![ Example { - description: "Keep two elements", - example: "echo [[editions]; [2015] [2018] [2021]] | keep 2", + description: "Take two elements", + example: "echo [[editions]; [2015] [2018] [2021]] | take 2", result: Some(Value::List { vals: vec![ Value::Record { @@ -48,8 +48,8 @@ impl Command for Keep { }), }, Example { - description: "Keep the first value", - example: "echo [2 4 6 8] | keep", + description: "Take the first value", + example: "echo [2 4 6 8] | take", result: Some(Value::List { vals: vec![Value::test_int(2)], span: Span::test_data(), @@ -94,12 +94,12 @@ impl Command for Keep { #[cfg(test)] mod tests { - use crate::Keep; + use crate::Take; #[test] fn test_examples() { use crate::test_examples; - test_examples(Keep {}) + test_examples(Take {}) } } diff --git a/crates/nu-command/src/filters/keep/keep_until.rs b/crates/nu-command/src/filters/take/take_until.rs similarity index 85% rename from crates/nu-command/src/filters/keep/keep_until.rs rename to crates/nu-command/src/filters/take/take_until.rs index 660acc4d75..bddc251c32 100644 --- a/crates/nu-command/src/filters/keep/keep_until.rs +++ b/crates/nu-command/src/filters/take/take_until.rs @@ -7,11 +7,11 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct KeepUntil; +pub struct TakeUntil; -impl Command for KeepUntil { +impl Command for TakeUntil { fn name(&self) -> &str { - "keep until" + "take until" } fn signature(&self) -> Signature { @@ -19,19 +19,19 @@ impl Command for KeepUntil { .required( "predicate", SyntaxShape::RowCondition, - "the predicate that kept element must not match", + "the predicate that element(s) must not match", ) .category(Category::Filters) } fn usage(&self) -> &str { - "Keep elements of the input until a predicate is true." + "Take elements of the input until a predicate is true." } fn examples(&self) -> Vec { vec![Example { - description: "Keep until the element is positive", - example: "echo [-1 -2 9 1] | keep until $it > 0", + description: "Take until the element is positive", + example: "echo [-1 -2 9 1] | take until $it > 0", result: Some(Value::List { vals: vec![Value::test_int(-1), Value::test_int(-2)], span: Span::test_data(), @@ -86,12 +86,12 @@ impl Command for KeepUntil { #[cfg(test)] mod tests { - use crate::KeepUntil; + use crate::TakeUntil; #[test] fn test_examples() { use crate::test_examples; - test_examples(KeepUntil) + test_examples(TakeUntil) } } diff --git a/crates/nu-command/src/filters/keep/keep_while.rs b/crates/nu-command/src/filters/take/take_while.rs similarity index 85% rename from crates/nu-command/src/filters/keep/keep_while.rs rename to crates/nu-command/src/filters/take/take_while.rs index 25a6c59392..67c7aa3835 100644 --- a/crates/nu-command/src/filters/keep/keep_while.rs +++ b/crates/nu-command/src/filters/take/take_while.rs @@ -7,11 +7,11 @@ use nu_protocol::{ }; #[derive(Clone)] -pub struct KeepWhile; +pub struct TakeWhile; -impl Command for KeepWhile { +impl Command for TakeWhile { fn name(&self) -> &str { - "keep while" + "take while" } fn signature(&self) -> Signature { @@ -19,19 +19,19 @@ impl Command for KeepWhile { .required( "predicate", SyntaxShape::RowCondition, - "the predicate that kept element must not match", + "the predicate that element(s) must match", ) .category(Category::Filters) } fn usage(&self) -> &str { - "Keep elements of the input while a predicate is true." + "Take elements of the input while a predicate is true." } fn examples(&self) -> Vec { vec![Example { - description: "Keep while the element is negative", - example: "echo [-1 -2 9 1] | keep while $it < 0", + description: "Take while the element is negative", + example: "echo [-1 -2 9 1] | take while $it < 0", result: Some(Value::List { vals: vec![Value::test_int(-1), Value::test_int(-2)], span: Span::test_data(), @@ -86,12 +86,12 @@ impl Command for KeepWhile { #[cfg(test)] mod tests { - use crate::KeepWhile; + use crate::TakeWhile; #[test] fn test_examples() { use crate::test_examples; - test_examples(KeepWhile) + test_examples(TakeWhile) } } diff --git a/crates/nu-command/tests/commands/mod.rs b/crates/nu-command/tests/commands/mod.rs index 3fa25a45e3..ba76af6239 100644 --- a/crates/nu-command/tests/commands/mod.rs +++ b/crates/nu-command/tests/commands/mod.rs @@ -27,7 +27,6 @@ mod histogram; mod insert; mod into_filesize; mod into_int; -mod keep; mod last; mod length; mod lines; @@ -60,6 +59,7 @@ mod split_by; mod split_column; mod split_row; mod str_; +mod take; mod touch; mod uniq; mod update; diff --git a/crates/nu-command/tests/commands/keep/mod.rs b/crates/nu-command/tests/commands/take/mod.rs similarity index 100% rename from crates/nu-command/tests/commands/keep/mod.rs rename to crates/nu-command/tests/commands/take/mod.rs diff --git a/crates/nu-command/tests/commands/keep/rows.rs b/crates/nu-command/tests/commands/take/rows.rs similarity index 89% rename from crates/nu-command/tests/commands/keep/rows.rs rename to crates/nu-command/tests/commands/take/rows.rs index 84df113770..a4b1a78f2d 100644 --- a/crates/nu-command/tests/commands/keep/rows.rs +++ b/crates/nu-command/tests/commands/take/rows.rs @@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline}; #[test] fn rows() { - Playground::setup("keep_test_1", |dirs, sandbox| { + Playground::setup("take_test_1", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "caballeros.csv", r#" @@ -20,7 +20,7 @@ fn rows() { cwd: dirs.test(), pipeline( r#" open caballeros.csv - | keep 3 + | take 3 | get lucky_code | math sum "# diff --git a/crates/nu-command/tests/commands/keep/until.rs b/crates/nu-command/tests/commands/take/until.rs similarity index 92% rename from crates/nu-command/tests/commands/keep/until.rs rename to crates/nu-command/tests/commands/take/until.rs index 13c90bbda3..aa129b09cc 100644 --- a/crates/nu-command/tests/commands/keep/until.rs +++ b/crates/nu-command/tests/commands/take/until.rs @@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("keep_until_test_1", |dirs, sandbox| { + Playground::setup("take_until_test_1", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "caballeros.txt", r#" @@ -39,7 +39,7 @@ fn condition_is_met() { | str collect (char nl) | from csv | skip while "Chicken Collection" != "Blue Chickens" - | keep until "Chicken Collection" == "Red Chickens" + | take until "Chicken Collection" == "Red Chickens" | skip 1 | into int "31/04/2020" | get "31/04/2020" diff --git a/crates/nu-command/tests/commands/keep/while_.rs b/crates/nu-command/tests/commands/take/while_.rs similarity index 92% rename from crates/nu-command/tests/commands/keep/while_.rs rename to crates/nu-command/tests/commands/take/while_.rs index de8f5855b3..c46673dc7f 100644 --- a/crates/nu-command/tests/commands/keep/while_.rs +++ b/crates/nu-command/tests/commands/take/while_.rs @@ -4,7 +4,7 @@ use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("keep_while_test_1", |dirs, sandbox| { + Playground::setup("take_while_test_1", |dirs, sandbox| { sandbox.with_files(vec![FileWithContentToBeTrimmed( "caballeros.txt", r#" @@ -39,7 +39,7 @@ fn condition_is_met() { | str collect (char nl) | from csv | skip 1 - | keep while "Chicken Collection" != "Blue Chickens" + | take while "Chicken Collection" != "Blue Chickens" | into int "31/04/2020" | get "31/04/2020" | math sum