From 0788fe5e72e86d690baf3420e7edc2ea5bc5e919 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 31 Mar 2023 13:23:22 -0500 Subject: [PATCH] fully deprecate str collect (#8680) # Description This PR fully deprecates `str collect`. It's been "half-deprecatd" for a long time. This takes it all the way and disallows the command in favor of `str join`. # User-Facing Changes No more `str collect` # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-utils/standard_library/tests.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- crates/nu-command/src/default_context.rs | 16 +-- crates/nu-command/src/deprecated/collect.rs | 34 +++++++ .../src/deprecated/deprecated_commands.rs | 1 + crates/nu-command/src/deprecated/mod.rs | 2 + crates/nu-command/src/strings/str_/collect.rs | 97 ------------------- crates/nu-command/src/strings/str_/mod.rs | 2 - 6 files changed, 45 insertions(+), 107 deletions(-) create mode 100644 crates/nu-command/src/deprecated/collect.rs delete mode 100644 crates/nu-command/src/strings/str_/collect.rs diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index a5395be84a..507f149d3d 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -183,7 +183,6 @@ pub fn create_default_context() -> EngineState { Str, StrCamelCase, StrCapitalize, - StrCollect, StrContains, StrDistance, StrDowncase, @@ -442,17 +441,18 @@ pub fn create_default_context() -> EngineState { // Deprecated bind_command! { + ExportOldAlias, HashBase64, LPadDeprecated, - RPadDeprecated, - Source, - StrDatetimeDeprecated, - StrDecimalDeprecated, - StrIntDeprecated, - StrFindReplaceDeprecated, MathEvalDeprecated, OldAlias, - ExportOldAlias, + RPadDeprecated, + Source, + StrCollectDeprecated, + StrDatetimeDeprecated, + StrDecimalDeprecated, + StrFindReplaceDeprecated, + StrIntDeprecated, }; working_set.render() diff --git a/crates/nu-command/src/deprecated/collect.rs b/crates/nu-command/src/deprecated/collect.rs new file mode 100644 index 0000000000..8e1b359a4f --- /dev/null +++ b/crates/nu-command/src/deprecated/collect.rs @@ -0,0 +1,34 @@ +use nu_protocol::ast::Call; +use nu_protocol::engine::{Command, EngineState, Stack}; +use nu_protocol::{Category, PipelineData, ShellError, Signature}; + +#[derive(Clone)] +pub struct StrCollectDeprecated; + +impl Command for StrCollectDeprecated { + fn name(&self) -> &str { + "str collect" + } + + fn signature(&self) -> Signature { + Signature::build(self.name()).category(Category::Deprecated) + } + + fn usage(&self) -> &str { + "Deprecated command." + } + + fn run( + &self, + _: &EngineState, + _: &mut Stack, + call: &Call, + _: PipelineData, + ) -> Result { + Err(nu_protocol::ShellError::DeprecatedCommand( + self.name().to_string(), + "str join".to_owned(), + call.head, + )) + } +} diff --git a/crates/nu-command/src/deprecated/deprecated_commands.rs b/crates/nu-command/src/deprecated/deprecated_commands.rs index c04c6b861c..6f39ecf3f1 100644 --- a/crates/nu-command/src/deprecated/deprecated_commands.rs +++ b/crates/nu-command/src/deprecated/deprecated_commands.rs @@ -23,5 +23,6 @@ pub fn deprecated_commands() -> HashMap { ("str lpad".to_string(), "fill".to_string()), ("str rpad".to_string(), "fill".to_string()), ("benchmark".to_string(), "timeit".to_string()), + ("str collect".to_string(), "str join".to_string()), ]) } diff --git a/crates/nu-command/src/deprecated/mod.rs b/crates/nu-command/src/deprecated/mod.rs index 6428cbabaf..a63676303c 100644 --- a/crates/nu-command/src/deprecated/mod.rs +++ b/crates/nu-command/src/deprecated/mod.rs @@ -1,3 +1,4 @@ +mod collect; mod deprecated_commands; mod export_old_alias; mod hash_base64; @@ -11,6 +12,7 @@ mod str_decimal; mod str_find_replace; mod str_int; +pub use collect::StrCollectDeprecated; pub use deprecated_commands::*; pub use export_old_alias::ExportOldAlias; pub use hash_base64::HashBase64; diff --git a/crates/nu-command/src/strings/str_/collect.rs b/crates/nu-command/src/strings/str_/collect.rs deleted file mode 100644 index 258ee64126..0000000000 --- a/crates/nu-command/src/strings/str_/collect.rs +++ /dev/null @@ -1,97 +0,0 @@ -use nu_engine::CallExt; -use nu_protocol::ast::Call; -use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{ - Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type, - Value, -}; - -#[derive(Clone)] -pub struct StrCollect; - -impl Command for StrCollect { - fn name(&self) -> &str { - "str collect" - } - - fn signature(&self) -> Signature { - Signature::build("str collect") - .input_output_types(vec![(Type::List(Box::new(Type::String)), Type::String)]) - .optional( - "separator", - SyntaxShape::String, - "optional separator to use when creating string", - ) - .category(Category::Deprecated) - } - - fn usage(&self) -> &str { - "Deprecated command." - } - - fn run( - &self, - engine_state: &EngineState, - stack: &mut Stack, - call: &Call, - input: PipelineData, - ) -> Result { - let separator: Option = call.opt(engine_state, stack, 0)?; - - let config = engine_state.get_config(); - - // let output = input.collect_string(&separator.unwrap_or_default(), &config)?; - // Hmm, not sure what we actually want. If you don't use debug_string, Date comes out as human readable - // which feels funny - let mut strings: Vec = vec![]; - - for value in input { - match value { - Value::Error { error } => { - return Err(*error); - } - value => { - strings.push(value.debug_string("\n", config)); - } - } - } - - let output = if let Some(separator) = separator { - strings.join(&separator) - } else { - strings.join("") - }; - - Ok(Value::String { - val: output, - span: call.head, - } - .into_pipeline_data()) - } - - fn examples(&self) -> Vec { - vec![ - Example { - description: "Create a string from input", - example: "['nu', 'shell'] | str collect", - result: Some(Value::test_string("nushell")), - }, - Example { - description: "Create a string from input with a separator", - example: "['nu', 'shell'] | str collect '-'", - result: Some(Value::test_string("nu-shell")), - }, - ] - } -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn test_examples() { - use crate::test_examples; - - test_examples(StrCollect {}) - } -} diff --git a/crates/nu-command/src/strings/str_/mod.rs b/crates/nu-command/src/strings/str_/mod.rs index b97557e9e7..e244144ac7 100644 --- a/crates/nu-command/src/strings/str_/mod.rs +++ b/crates/nu-command/src/strings/str_/mod.rs @@ -1,5 +1,4 @@ mod case; -mod collect; mod contains; mod distance; mod ends_with; @@ -13,7 +12,6 @@ mod substring; mod trim; pub use case::*; -pub use collect::*; pub use contains::SubCommand as StrContains; pub use distance::SubCommand as StrDistance; pub use ends_with::SubCommand as StrEndswith;