From 075535f86981d40dfa99836a800833606db66cbc Mon Sep 17 00:00:00 2001 From: Brage Ingebrigtsen <84551201+Skyppex@users.noreply.github.com> Date: Sun, 12 May 2024 01:13:36 +0200 Subject: [PATCH] remove --not flag for 'str contains' (#12837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR resolves an inconsistency between different `str` subcommands, notably `str contains`, `str starts-with` and `str ends-with`. Only the `str contains` command has the `--not` flag and a desicion was made in this #12781 PR to remove the `--not` flag and use the `not` operator instead. Before: `"blob" | str contains --not o` After: `not ("blob" | str contains o)` OR `"blob" | str contains o | not $in` > Note, you can currently do all three, but the first will be broken after this PR is merged. # User-Facing Changes - remove `--not(-n)` flag from `str contains` command - This is a breaking change! # Tests + Formatting - [x] Added tests - [x] Ran `cargo fmt --all` - [x] Ran `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` - [x] Ran `cargo test --workspace` - [ ] Ran `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` - I was unable to get this working. ``` Error: nu::parser::export_not_found × Export not found. ╭─[source:1:9] 1 │ use std testing; testing run-tests --path crates/nu-std · ───┬─── · ╰── could not find imports ╰──── ``` ^ I still can't figure out how to make this work 😂 # After Submitting Requires update of documentation --- .../nu-command/src/strings/str_/contains.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/crates/nu-command/src/strings/str_/contains.rs b/crates/nu-command/src/strings/str_/contains.rs index abb0ce1a2b..bc1d5bcf11 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -40,7 +40,7 @@ impl Command for SubCommand { "For a data structure input, check strings at the given cell paths, and replace with result.", ) .switch("ignore-case", "search is case insensitive", Some('i')) - .switch("not", "does not contain", Some('n')) + .switch("not", "DEPRECATED OPTION: does not contain", Some('n')) .category(Category::Strings) } @@ -59,6 +59,20 @@ impl Command for SubCommand { call: &Call, input: PipelineData, ) -> Result { + if call.has_flag(engine_state, stack, "not")? { + nu_protocol::report_error_new( + engine_state, + &ShellError::GenericError { + error: "Deprecated option".into(), + msg: "`str contains --not {string}` is deprecated and will be removed in 0.95." + .into(), + span: Some(call.head), + help: Some("Please use the `not` operator instead.".into()), + inner: vec![], + }, + ); + } + let cell_paths: Vec = call.rest(engine_state, stack, 1)?; let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths); let args = Arguments { @@ -120,15 +134,6 @@ impl Command for SubCommand { Value::test_bool(false), ])), }, - Example { - description: "Check if list does not contain string", - example: "[one two three] | str contains --not o", - result: Some(Value::test_list(vec![ - Value::test_bool(false), - Value::test_bool(false), - Value::test_bool(true), - ])), - }, ] } }