mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
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.
This commit is contained in:
parent
b2257a5ca3
commit
0788fe5e72
@ -183,7 +183,6 @@ pub fn create_default_context() -> EngineState {
|
|||||||
Str,
|
Str,
|
||||||
StrCamelCase,
|
StrCamelCase,
|
||||||
StrCapitalize,
|
StrCapitalize,
|
||||||
StrCollect,
|
|
||||||
StrContains,
|
StrContains,
|
||||||
StrDistance,
|
StrDistance,
|
||||||
StrDowncase,
|
StrDowncase,
|
||||||
@ -442,17 +441,18 @@ pub fn create_default_context() -> EngineState {
|
|||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
bind_command! {
|
bind_command! {
|
||||||
|
ExportOldAlias,
|
||||||
HashBase64,
|
HashBase64,
|
||||||
LPadDeprecated,
|
LPadDeprecated,
|
||||||
RPadDeprecated,
|
|
||||||
Source,
|
|
||||||
StrDatetimeDeprecated,
|
|
||||||
StrDecimalDeprecated,
|
|
||||||
StrIntDeprecated,
|
|
||||||
StrFindReplaceDeprecated,
|
|
||||||
MathEvalDeprecated,
|
MathEvalDeprecated,
|
||||||
OldAlias,
|
OldAlias,
|
||||||
ExportOldAlias,
|
RPadDeprecated,
|
||||||
|
Source,
|
||||||
|
StrCollectDeprecated,
|
||||||
|
StrDatetimeDeprecated,
|
||||||
|
StrDecimalDeprecated,
|
||||||
|
StrFindReplaceDeprecated,
|
||||||
|
StrIntDeprecated,
|
||||||
};
|
};
|
||||||
|
|
||||||
working_set.render()
|
working_set.render()
|
||||||
|
34
crates/nu-command/src/deprecated/collect.rs
Normal file
34
crates/nu-command/src/deprecated/collect.rs
Normal file
@ -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<PipelineData, ShellError> {
|
||||||
|
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||||
|
self.name().to_string(),
|
||||||
|
"str join".to_owned(),
|
||||||
|
call.head,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
@ -23,5 +23,6 @@ pub fn deprecated_commands() -> HashMap<String, String> {
|
|||||||
("str lpad".to_string(), "fill".to_string()),
|
("str lpad".to_string(), "fill".to_string()),
|
||||||
("str rpad".to_string(), "fill".to_string()),
|
("str rpad".to_string(), "fill".to_string()),
|
||||||
("benchmark".to_string(), "timeit".to_string()),
|
("benchmark".to_string(), "timeit".to_string()),
|
||||||
|
("str collect".to_string(), "str join".to_string()),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
mod collect;
|
||||||
mod deprecated_commands;
|
mod deprecated_commands;
|
||||||
mod export_old_alias;
|
mod export_old_alias;
|
||||||
mod hash_base64;
|
mod hash_base64;
|
||||||
@ -11,6 +12,7 @@ mod str_decimal;
|
|||||||
mod str_find_replace;
|
mod str_find_replace;
|
||||||
mod str_int;
|
mod str_int;
|
||||||
|
|
||||||
|
pub use collect::StrCollectDeprecated;
|
||||||
pub use deprecated_commands::*;
|
pub use deprecated_commands::*;
|
||||||
pub use export_old_alias::ExportOldAlias;
|
pub use export_old_alias::ExportOldAlias;
|
||||||
pub use hash_base64::HashBase64;
|
pub use hash_base64::HashBase64;
|
||||||
|
@ -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<PipelineData, ShellError> {
|
|
||||||
let separator: Option<String> = 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<String> = 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<Example> {
|
|
||||||
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 {})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
mod case;
|
mod case;
|
||||||
mod collect;
|
|
||||||
mod contains;
|
mod contains;
|
||||||
mod distance;
|
mod distance;
|
||||||
mod ends_with;
|
mod ends_with;
|
||||||
@ -13,7 +12,6 @@ mod substring;
|
|||||||
mod trim;
|
mod trim;
|
||||||
|
|
||||||
pub use case::*;
|
pub use case::*;
|
||||||
pub use collect::*;
|
|
||||||
pub use contains::SubCommand as StrContains;
|
pub use contains::SubCommand as StrContains;
|
||||||
pub use distance::SubCommand as StrDistance;
|
pub use distance::SubCommand as StrDistance;
|
||||||
pub use ends_with::SubCommand as StrEndswith;
|
pub use ends_with::SubCommand as StrEndswith;
|
||||||
|
Loading…
Reference in New Issue
Block a user