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,
cell_paths: Option<Vec<CellPath>>,
case_insensitive: bool,
not_contain: bool,
}
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.",
)
.switch("ignore-case", "search is case insensitive", Some('i'))
.switch("not", "DEPRECATED OPTION: does not contain", Some('n'))
.category(Category::Strings)
}
@ -63,27 +61,12 @@ impl Command for SubCommand {
call: &Call,
input: PipelineData,
) -> 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 = (!cell_paths.is_empty()).then_some(cell_paths);
let args = Arguments {
substring: call.req::<String>(engine_state, stack, 0)?,
cell_paths,
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())
}
@ -114,7 +97,6 @@ impl Command for SubCommand {
substring: call.req_const::<String>(working_set, 0)?,
cell_paths,
case_insensitive: call.has_flag_const(working_set, "ignore-case")?,
not_contain: call.has_flag_const(working_set, "not")?,
};
operate(
action,
@ -183,7 +165,6 @@ fn action(
input: &Value,
Arguments {
case_insensitive,
not_contain,
substring,
..
}: &Arguments,
@ -191,23 +172,11 @@ fn action(
) -> Value {
match input {
Value::String { val, .. } => Value::bool(
match case_insensitive {
true => {
if *not_contain {
!val.to_folded_case()
.contains(substring.to_folded_case().as_str())
} else {
val.to_folded_case()
.contains(substring.to_folded_case().as_str())
}
}
false => {
if *not_contain {
!val.contains(substring)
} else {
val.contains(substring)
}
}
if *case_insensitive {
val.to_folded_case()
.contains(substring.to_folded_case().as_str())
} else {
val.contains(substring)
},
head,
),