From 3e09158afcba9345e947362e464b56ca82068946 Mon Sep 17 00:00:00 2001 From: krober Date: Tue, 17 May 2022 23:55:43 -0500 Subject: [PATCH] Move capitalize, downcase, upcase to /cases; fix some example descriptions; clarify usage text (#5572) Co-authored-by: kyle --- .../nu-command/src/strings/str_/{ => case}/capitalize.rs | 2 +- crates/nu-command/src/strings/str_/{ => case}/downcase.rs | 0 crates/nu-command/src/strings/str_/case/mod.rs | 6 ++++++ .../src/strings/str_/case/screaming_snake_case.rs | 6 +++--- crates/nu-command/src/strings/str_/case/snake_case.rs | 8 ++++---- crates/nu-command/src/strings/str_/case/str_.rs | 2 +- crates/nu-command/src/strings/str_/{ => case}/upcase.rs | 0 crates/nu-command/src/strings/str_/index_of.rs | 2 +- crates/nu-command/src/strings/str_/mod.rs | 6 ------ 9 files changed, 16 insertions(+), 16 deletions(-) rename crates/nu-command/src/strings/str_/{ => case}/capitalize.rs (99%) rename crates/nu-command/src/strings/str_/{ => case}/downcase.rs (100%) rename crates/nu-command/src/strings/str_/{ => case}/upcase.rs (100%) diff --git a/crates/nu-command/src/strings/str_/capitalize.rs b/crates/nu-command/src/strings/str_/case/capitalize.rs similarity index 99% rename from crates/nu-command/src/strings/str_/capitalize.rs rename to crates/nu-command/src/strings/str_/case/capitalize.rs index 4d1a43468a..be584c0be8 100644 --- a/crates/nu-command/src/strings/str_/capitalize.rs +++ b/crates/nu-command/src/strings/str_/case/capitalize.rs @@ -24,7 +24,7 @@ impl Command for SubCommand { } fn usage(&self) -> &str { - "Capitalize text" + "Capitalize first letter of text" } fn run( diff --git a/crates/nu-command/src/strings/str_/downcase.rs b/crates/nu-command/src/strings/str_/case/downcase.rs similarity index 100% rename from crates/nu-command/src/strings/str_/downcase.rs rename to crates/nu-command/src/strings/str_/case/downcase.rs diff --git a/crates/nu-command/src/strings/str_/case/mod.rs b/crates/nu-command/src/strings/str_/case/mod.rs index 9fb318b91c..b4df44a497 100644 --- a/crates/nu-command/src/strings/str_/case/mod.rs +++ b/crates/nu-command/src/strings/str_/case/mod.rs @@ -1,16 +1,22 @@ pub mod camel_case; +pub mod capitalize; +pub mod downcase; pub mod kebab_case; pub mod pascal_case; pub mod screaming_snake_case; pub mod snake_case; pub mod str_; +pub mod upcase; pub use camel_case::SubCommand as StrCamelCase; +pub use capitalize::SubCommand as StrCapitalize; +pub use downcase::SubCommand as StrDowncase; pub use kebab_case::SubCommand as StrKebabCase; pub use pascal_case::SubCommand as StrPascalCase; pub use screaming_snake_case::SubCommand as StrScreamingSnakeCase; pub use snake_case::SubCommand as StrSnakeCase; pub use str_::Str; +pub use upcase::SubCommand as StrUpcase; use nu_engine::CallExt; diff --git a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs index ce014279ee..6950615116 100644 --- a/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/screaming_snake_case.rs @@ -41,7 +41,7 @@ impl Command for SubCommand { fn examples(&self) -> Vec { vec![ Example { - description: "convert a string to camelCase", + description: "convert a string to SCREAMING_SNAKE_CASE", example: r#" "NuShell" | str screaming-snake-case"#, result: Some(Value::String { val: "NU_SHELL".to_string(), @@ -49,7 +49,7 @@ impl Command for SubCommand { }), }, Example { - description: "convert a string to camelCase", + description: "convert a string to SCREAMING_SNAKE_CASE", example: r#" "this_is_the_second_case" | str screaming-snake-case"#, result: Some(Value::String { val: "THIS_IS_THE_SECOND_CASE".to_string(), @@ -57,7 +57,7 @@ impl Command for SubCommand { }), }, Example { - description: "convert a string to camelCase", + description: "convert a string to SCREAMING_SNAKE_CASE", example: r#""this-is-the-first-case" | str screaming-snake-case"#, result: Some(Value::String { val: "THIS_IS_THE_FIRST_CASE".to_string(), diff --git a/crates/nu-command/src/strings/str_/case/snake_case.rs b/crates/nu-command/src/strings/str_/case/snake_case.rs index f5b515ce5d..5891eabed3 100644 --- a/crates/nu-command/src/strings/str_/case/snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/snake_case.rs @@ -40,7 +40,7 @@ impl Command for SubCommand { fn examples(&self) -> Vec { vec![ Example { - description: "convert a string to camelCase", + description: "convert a string to snake_case", example: r#" "NuShell" | str snake-case"#, result: Some(Value::String { val: "nu_shell".to_string(), @@ -48,7 +48,7 @@ impl Command for SubCommand { }), }, Example { - description: "convert a string to camelCase", + description: "convert a string to snake_case", example: r#" "this_is_the_second_case" | str snake-case"#, result: Some(Value::String { val: "this_is_the_second_case".to_string(), @@ -56,7 +56,7 @@ impl Command for SubCommand { }), }, Example { - description: "convert a string to camelCase", + description: "convert a string to snake_case", example: r#""this-is-the-first-case" | str snake-case"#, result: Some(Value::String { val: "this_is_the_first_case".to_string(), @@ -64,7 +64,7 @@ impl Command for SubCommand { }), }, Example { - description: "convert a column from a table to snake-case", + description: "convert a column from a table to snake_case", example: r#"[[lang, gems]; [nuTest, 100]] | str snake-case lang"#, result: Some(Value::List { vals: vec![Value::Record { diff --git a/crates/nu-command/src/strings/str_/case/str_.rs b/crates/nu-command/src/strings/str_/case/str_.rs index 153f580928..72198a5b41 100644 --- a/crates/nu-command/src/strings/str_/case/str_.rs +++ b/crates/nu-command/src/strings/str_/case/str_.rs @@ -18,7 +18,7 @@ impl Command for Str { } fn usage(&self) -> &str { - "Various commands for working with string data." + "Various commands for working with string data" } fn run( diff --git a/crates/nu-command/src/strings/str_/upcase.rs b/crates/nu-command/src/strings/str_/case/upcase.rs similarity index 100% rename from crates/nu-command/src/strings/str_/upcase.rs rename to crates/nu-command/src/strings/str_/case/upcase.rs diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 26c46648d4..c4a57eb7e4 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -48,7 +48,7 @@ impl Command for SubCommand { } fn usage(&self) -> &str { - "Returns starting index of given pattern in string counting from 0. Returns -1 when there are no results." + "Returns start index of first occurrence of pattern in string, or -1 if no match" } fn run( diff --git a/crates/nu-command/src/strings/str_/mod.rs b/crates/nu-command/src/strings/str_/mod.rs index ba60aeeae5..559946e42e 100644 --- a/crates/nu-command/src/strings/str_/mod.rs +++ b/crates/nu-command/src/strings/str_/mod.rs @@ -1,8 +1,6 @@ -mod capitalize; mod case; mod collect; mod contains; -mod downcase; mod ends_with; mod index_of; mod length; @@ -13,13 +11,10 @@ mod rpad; mod starts_with; mod substring; mod trim; -mod upcase; -pub use capitalize::SubCommand as StrCapitalize; pub use case::*; pub use collect::*; pub use contains::SubCommand as StrContains; -pub use downcase::SubCommand as StrDowncase; pub use ends_with::SubCommand as StrEndswith; pub use index_of::SubCommand as StrIndexOf; pub use length::SubCommand as StrLength; @@ -30,4 +25,3 @@ pub use rpad::SubCommand as StrRpad; pub use starts_with::SubCommand as StrStartsWith; pub use substring::SubCommand as StrSubstring; pub use trim::Trim as StrTrim; -pub use upcase::SubCommand as StrUpcase;