Evolve StrCollect into StrJoin

This commit is contained in:
Dan Davison 2022-09-09 14:35:49 -04:00
parent 28cb644a8a
commit 87b82f68fe
4 changed files with 13 additions and 10 deletions

View File

@ -200,6 +200,7 @@ pub fn create_default_context() -> EngineState {
StrDistance, StrDistance,
StrDowncase, StrDowncase,
StrEndswith, StrEndswith,
StrJoin,
StrReplace, StrReplace,
StrIndexOf, StrIndexOf,
StrKebabCase, StrKebabCase,

View File

@ -14,7 +14,7 @@ use crate::To;
#[cfg(test)] #[cfg(test)]
use super::{ use super::{
Ansi, Date, From, If, Into, LetEnv, Math, Path, Random, Split, SplitColumn, SplitRow, Str, Ansi, Date, From, If, Into, LetEnv, Math, Path, Random, Split, SplitColumn, SplitRow, Str,
StrCollect, StrLength, StrReplace, Url, Wrap, StrJoin, StrLength, StrReplace, Url, Wrap,
}; };
#[cfg(test)] #[cfg(test)]
@ -29,7 +29,7 @@ pub fn test_examples(cmd: impl Command + 'static) {
// Try to keep this working set small to keep tests running as fast as possible // Try to keep this working set small to keep tests running as fast as possible
let mut working_set = StateWorkingSet::new(&*engine_state); let mut working_set = StateWorkingSet::new(&*engine_state);
working_set.add_decl(Box::new(Str)); working_set.add_decl(Box::new(Str));
working_set.add_decl(Box::new(StrCollect)); working_set.add_decl(Box::new(StrJoin));
working_set.add_decl(Box::new(StrLength)); working_set.add_decl(Box::new(StrLength));
working_set.add_decl(Box::new(StrReplace)); working_set.add_decl(Box::new(StrReplace));
working_set.add_decl(Box::new(BuildString)); working_set.add_decl(Box::new(BuildString));

View File

@ -7,15 +7,15 @@ use nu_protocol::{
}; };
#[derive(Clone)] #[derive(Clone)]
pub struct StrCollect; pub struct StrJoin;
impl Command for StrCollect { impl Command for StrJoin {
fn name(&self) -> &str { fn name(&self) -> &str {
"str collect" "str join"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("str collect") Signature::build("str join")
.optional( .optional(
"separator", "separator",
SyntaxShape::String, SyntaxShape::String,
@ -29,7 +29,7 @@ impl Command for StrCollect {
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {
vec!["join", "concatenate"] vec!["collect", "concatenate"]
} }
fn run( fn run(
@ -76,7 +76,7 @@ impl Command for StrCollect {
vec![ vec![
Example { Example {
description: "Create a string from input", description: "Create a string from input",
example: "['nu', 'shell'] | str collect", example: "['nu', 'shell'] | str join",
result: Some(Value::String { result: Some(Value::String {
val: "nushell".to_string(), val: "nushell".to_string(),
span: Span::test_data(), span: Span::test_data(),
@ -84,7 +84,7 @@ impl Command for StrCollect {
}, },
Example { Example {
description: "Create a string from input with a separator", description: "Create a string from input with a separator",
example: "['nu', 'shell'] | str collect '-'", example: "['nu', 'shell'] | str join '-'",
result: Some(Value::String { result: Some(Value::String {
val: "nu-shell".to_string(), val: "nu-shell".to_string(),
span: Span::test_data(), span: Span::test_data(),
@ -101,6 +101,6 @@ mod tests {
fn test_examples() { fn test_examples() {
use crate::test_examples; use crate::test_examples;
test_examples(StrCollect {}) test_examples(StrJoin {})
} }
} }

View File

@ -4,6 +4,7 @@ mod contains;
mod distance; mod distance;
mod ends_with; mod ends_with;
mod index_of; mod index_of;
mod join;
mod length; mod length;
mod lpad; mod lpad;
mod replace; mod replace;
@ -19,6 +20,7 @@ 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;
pub use index_of::SubCommand as StrIndexOf; pub use index_of::SubCommand as StrIndexOf;
pub use join::*;
pub use length::SubCommand as StrLength; pub use length::SubCommand as StrLength;
pub use lpad::SubCommand as StrLpad; pub use lpad::SubCommand as StrLpad;
pub use replace::SubCommand as StrReplace; pub use replace::SubCommand as StrReplace;