Remove deprecated --not flag on str contains (#13124)

# Description
Removes the `str contains --not` flag that was deprecated in the last
minor release.

# User-Facing Changes
Breaking change since a flag was removed.
This commit is contained in:
Ian Manske 2024-06-11 19:00:00 +00:00 committed by GitHub
parent a8376fad40
commit b0d1b4b182
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,7 +10,6 @@ struct Arguments {
substring: String, substring: String,
cell_paths: Option<Vec<CellPath>>, cell_paths: Option<Vec<CellPath>>,
case_insensitive: bool, case_insensitive: bool,
not_contain: bool,
} }
impl CmdArgument for Arguments { impl CmdArgument for Arguments {
@ -40,7 +39,6 @@ impl Command for SubCommand {
"For a data structure input, check strings at the given cell paths, and replace with result.", "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("ignore-case", "search is case insensitive", Some('i'))
.switch("not", "DEPRECATED OPTION: does not contain", Some('n'))
.category(Category::Strings) .category(Category::Strings)
} }
@ -63,27 +61,12 @@ impl Command for SubCommand {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
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<CellPath> = call.rest(engine_state, stack, 1)?; let cell_paths: Vec<CellPath> = call.rest(engine_state, stack, 1)?;
let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths); let cell_paths = (!cell_paths.is_empty()).then_some(cell_paths);
let args = Arguments { let args = Arguments {
substring: call.req::<String>(engine_state, stack, 0)?, substring: call.req::<String>(engine_state, stack, 0)?,
cell_paths, cell_paths,
case_insensitive: call.has_flag(engine_state, stack, "ignore-case")?, case_insensitive: call.has_flag(engine_state, stack, "ignore-case")?,
not_contain: call.has_flag(engine_state, stack, "not")?,
}; };
operate(action, args, input, call.head, engine_state.ctrlc.clone()) operate(action, args, input, call.head, engine_state.ctrlc.clone())
} }
@ -114,7 +97,6 @@ impl Command for SubCommand {
substring: call.req_const::<String>(working_set, 0)?, substring: call.req_const::<String>(working_set, 0)?,
cell_paths, cell_paths,
case_insensitive: call.has_flag_const(working_set, "ignore-case")?, case_insensitive: call.has_flag_const(working_set, "ignore-case")?,
not_contain: call.has_flag_const(working_set, "not")?,
}; };
operate( operate(
action, action,
@ -183,7 +165,6 @@ fn action(
input: &Value, input: &Value,
Arguments { Arguments {
case_insensitive, case_insensitive,
not_contain,
substring, substring,
.. ..
}: &Arguments, }: &Arguments,
@ -191,23 +172,11 @@ fn action(
) -> Value { ) -> Value {
match input { match input {
Value::String { val, .. } => Value::bool( Value::String { val, .. } => Value::bool(
match case_insensitive { if *case_insensitive {
true => { val.to_folded_case()
if *not_contain { .contains(substring.to_folded_case().as_str())
!val.to_folded_case() } else {
.contains(substring.to_folded_case().as_str()) val.contains(substring)
} else {
val.to_folded_case()
.contains(substring.to_folded_case().as_str())
}
}
false => {
if *not_contain {
!val.contains(substring)
} else {
val.contains(substring)
}
}
}, },
head, head,
), ),