From c01f2ee0e96f4a760129a97d3b02e7a1c37f69f8 Mon Sep 17 00:00:00 2001 From: "A. Taha Baki" Date: Fri, 21 Jul 2023 02:51:25 +0300 Subject: [PATCH] str-expand: new capability, empty collection item (#9750) I added a new capability to `bracoxide` which is for `brace expansion` (it's almost like bash brace expressions). Anyway, this change adds this capability: `A{,B,C} | str expand`, returns: ```md - A - AB - AC ``` `A{B,,C} | str expand`, returns: ```md - AB - A - AC ``` `A{B,C,} | str expand`, returns: ```md - AB - AC - A ``` Updated examples, according to the new feature. --- Cargo.lock | 4 +- crates/nu-command/Cargo.toml | 2 +- crates/nu-command/src/strings/str_/expand.rs | 39 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 515bce2980..2feb67ae09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,9 +372,9 @@ dependencies = [ [[package]] name = "bracoxide" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "218d42d1e9cdf071a7badff501a139dd6f598fe21348e5e5c4e2302e43bdcefb" +checksum = "ae76c117551a0459f61c57b573271778214287482c346d14591d2ea250ecbea5" [[package]] name = "brotli" diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index e4eab6328a..5e05717e63 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -94,7 +94,7 @@ url = "2.2" uuid = { version = "1.3", features = ["v4"] } wax = { version = "0.5" } which = { version = "4.4", optional = true } -bracoxide = "0.1.0" +bracoxide = "0.1.1" [target.'cfg(windows)'.dependencies] winreg = "0.50" diff --git a/crates/nu-command/src/strings/str_/expand.rs b/crates/nu-command/src/strings/str_/expand.rs index 48dceacfbc..5b2e084dad 100644 --- a/crates/nu-command/src/strings/str_/expand.rs +++ b/crates/nu-command/src/strings/str_/expand.rs @@ -69,6 +69,45 @@ impl Command for SubCommand { },) }, + Example { + description: "Collection may include an empty item. It can be put at the start of the list.", + example: "\"A{,B,C}\" | str expand", + result: Some(Value::List{ + vals: vec![ + Value::test_string("A"), + Value::test_string("AB"), + Value::test_string("AC"), + ], + span: Span::test_data() + },) + }, + + Example { + description: "Empty item can be at the end of the collection.", + example: "\"A{B,C,}\" | str expand", + result: Some(Value::List{ + vals: vec![ + Value::test_string("AB"), + Value::test_string("AC"), + Value::test_string("A"), + ], + span: Span::test_data() + },) + }, + + Example { + description: "Empty item can be in the middle of the collection.", + example: "\"A{B,,C}\" | str expand", + result: Some(Value::List{ + vals: vec![ + Value::test_string("AB"), + Value::test_string("A"), + Value::test_string("AC"), + ], + span: Span::test_data() + },) + }, + Example { description: "Also, it is possible to use one inside another. Here is a real-world example, that creates files:", example: "\"A{B{1,3},C{2,5}}D\" | str expand",