From d9230a76f3db753fc9bde16041d7c2e2af4aee62 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Wed, 26 Jul 2023 23:13:57 +0200 Subject: [PATCH] Fix signatures for cellpath access of records (#9793) # Description The same procedure as for #9778 repeated for records. # User-Facing Changes Commands that directly supported applying their work directly to record fields via cell paths, that worked before #9680 will now work again # Tests + Formatting Tried to limit the need to add new `.allow_variants_without_examples()` by adjusting or adding tests to also use some records with access. --- crates/nu-cmd-extra/src/extra/bits/into.rs | 1 + crates/nu-cmd-extra/src/extra/bytes/add.rs | 1 + crates/nu-cmd-extra/src/extra/bytes/at.rs | 11 ++++++----- crates/nu-cmd-extra/src/extra/bytes/ends_with.rs | 1 + crates/nu-cmd-extra/src/extra/bytes/index_of.rs | 2 ++ crates/nu-cmd-extra/src/extra/bytes/length.rs | 1 + crates/nu-cmd-extra/src/extra/bytes/remove.rs | 11 +++++------ crates/nu-cmd-extra/src/extra/bytes/replace.rs | 2 ++ crates/nu-cmd-extra/src/extra/bytes/reverse.rs | 1 + .../nu-cmd-extra/src/extra/bytes/starts_with.rs | 1 + .../src/extra/platform/ansi/gradient.rs | 1 + .../src/extra/strings/encode_decode/decode_hex.rs | 1 + .../src/extra/strings/encode_decode/encode_hex.rs | 1 + .../src/extra/strings/format/filesize.rs | 1 + crates/nu-command/src/conversions/into/binary.rs | 1 + crates/nu-command/src/conversions/into/bool.rs | 1 + .../nu-command/src/conversions/into/datetime.rs | 1 + crates/nu-command/src/conversions/into/decimal.rs | 1 + .../nu-command/src/conversions/into/duration.rs | 2 ++ .../nu-command/src/conversions/into/filesize.rs | 1 + crates/nu-command/src/conversions/into/int.rs | 1 + crates/nu-command/src/conversions/into/string.rs | 1 + crates/nu-command/src/hash/generic_digest.rs | 1 + crates/nu-command/src/network/url/encode.rs | 1 + crates/nu-command/src/network/url/parse.rs | 1 + crates/nu-command/src/platform/ansi/strip.rs | 1 + .../src/strings/encode_decode/decode_base64.rs | 1 + .../src/strings/encode_decode/encode_base64.rs | 1 + .../src/strings/str_/case/camel_case.rs | 1 + .../src/strings/str_/case/capitalize.rs | 1 + .../nu-command/src/strings/str_/case/downcase.rs | 1 + .../src/strings/str_/case/kebab_case.rs | 1 + .../src/strings/str_/case/pascal_case.rs | 1 + .../src/strings/str_/case/screaming_snake_case.rs | 1 + .../src/strings/str_/case/snake_case.rs | 1 + .../src/strings/str_/case/title_case.rs | 1 + crates/nu-command/src/strings/str_/case/upcase.rs | 1 + crates/nu-command/src/strings/str_/contains.rs | 14 ++++++-------- crates/nu-command/src/strings/str_/distance.rs | 14 +++++++++++++- crates/nu-command/src/strings/str_/ends_with.rs | 1 + crates/nu-command/src/strings/str_/index_of.rs | 1 + crates/nu-command/src/strings/str_/length.rs | 1 + crates/nu-command/src/strings/str_/replace.rs | 15 +++++++++++++++ crates/nu-command/src/strings/str_/reverse.rs | 1 + crates/nu-command/src/strings/str_/starts_with.rs | 1 + crates/nu-command/src/strings/str_/substring.rs | 7 ++++++- crates/nu-command/src/strings/str_/trim/trim_.rs | 1 + 47 files changed, 95 insertions(+), 21 deletions(-) diff --git a/crates/nu-cmd-extra/src/extra/bits/into.rs b/crates/nu-cmd-extra/src/extra/bits/into.rs index 1c466f718d..9db8312613 100644 --- a/crates/nu-cmd-extra/src/extra/bits/into.rs +++ b/crates/nu-cmd-extra/src/extra/bits/into.rs @@ -37,6 +37,7 @@ impl Command for BitsInto { (Type::Bool, Type::String), (Type::Date, Type::String), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) // TODO: supply exhaustive examples .rest( diff --git a/crates/nu-cmd-extra/src/extra/bytes/add.rs b/crates/nu-cmd-extra/src/extra/bytes/add.rs index f5689e78f4..1a64762481 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/add.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/add.rs @@ -37,6 +37,7 @@ impl Command for BytesAdd { Type::List(Box::new(Type::Binary)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-cmd-extra/src/extra/bytes/at.rs b/crates/nu-cmd-extra/src/extra/bytes/at.rs index f588d9eb95..180d319bc1 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/at.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/at.rs @@ -44,6 +44,7 @@ impl Command for BytesAt { Type::List(Box::new(Type::Binary)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .required("range", SyntaxShape::Range, "the range to get bytes") @@ -108,11 +109,11 @@ impl Command for BytesAt { }, Example { description: "Get the remaining characters from a starting index", - example: " 0x[33 44 55 10 01 13] | bytes at 3..", - result: Some(Value::Binary { - val: vec![0x10, 0x01, 0x13], - span: Span::test_data(), - }), + example: " { data: 0x[33 44 55 10 01 13] } | bytes at 3.. data", + result: Some(Value::test_record( + vec!["data"], + vec![Value::test_binary(vec![0x10, 0x01, 0x13])], + )), }, Example { description: "Get the characters from the beginning until ending index", diff --git a/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs b/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs index cb16435aa7..0a12cbbae4 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs @@ -30,6 +30,7 @@ impl Command for BytesEndsWith { Signature::build("bytes ends-with") .input_output_types(vec![(Type::Binary, Type::Bool), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "the pattern to match") diff --git a/crates/nu-cmd-extra/src/extra/bytes/index_of.rs b/crates/nu-cmd-extra/src/extra/bytes/index_of.rs index 0090f46112..03c2981603 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/index_of.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/index_of.rs @@ -35,7 +35,9 @@ impl Command for BytesIndexOf { // FIXME: this shouldn't be needed, cell paths should work with the two // above (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) + .allow_variants_without_examples(true) .required( "pattern", SyntaxShape::Binary, diff --git a/crates/nu-cmd-extra/src/extra/bytes/length.rs b/crates/nu-cmd-extra/src/extra/bytes/length.rs index f672387cb8..11e22eb1c2 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/length.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/length.rs @@ -23,6 +23,7 @@ impl Command for BytesLen { Type::List(Box::new(Type::Int)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-cmd-extra/src/extra/bytes/remove.rs b/crates/nu-cmd-extra/src/extra/bytes/remove.rs index 8db1af62b5..86f3d7e732 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/remove.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/remove.rs @@ -33,6 +33,7 @@ impl Command for BytesRemove { .input_output_types(vec![ (Type::Binary, Type::Binary), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .required("pattern", SyntaxShape::Binary, "the pattern to find") .rest( @@ -92,12 +93,10 @@ impl Command for BytesRemove { }), }, Example { - description: "Remove all occurrences of find binary", - example: "0x[10 AA 10 BB 10] | bytes remove -a 0x[10]", - result: Some(Value::Binary { - val: vec![0xAA, 0xBB], - span: Span::test_data(), - }), + description: "Remove all occurrences of find binary in record field", + example: "{ data: 0x[10 AA 10 BB 10] } | bytes remove -a 0x[10] data", + result: Some(Value::test_record(vec!["data"], + vec![Value::test_binary(vec![0xAA, 0xBB])])), }, Example { description: "Remove occurrences of find binary from end", diff --git a/crates/nu-cmd-extra/src/extra/bytes/replace.rs b/crates/nu-cmd-extra/src/extra/bytes/replace.rs index 2370d13eb1..ee47a0c54f 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/replace.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/replace.rs @@ -33,7 +33,9 @@ impl Command for BytesReplace { .input_output_types(vec![ (Type::Binary, Type::Binary), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) + .allow_variants_without_examples(true) .required("find", SyntaxShape::Binary, "the pattern to find") .required("replace", SyntaxShape::Binary, "the replacement pattern") .rest( diff --git a/crates/nu-cmd-extra/src/extra/bytes/reverse.rs b/crates/nu-cmd-extra/src/extra/bytes/reverse.rs index 08d0b700cb..437d0fb466 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/reverse.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/reverse.rs @@ -20,6 +20,7 @@ impl Command for BytesReverse { .input_output_types(vec![ (Type::Binary, Type::Binary), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs b/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs index 85e64f1374..dc1d6acc10 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs @@ -32,6 +32,7 @@ impl Command for BytesStartsWith { .input_output_types(vec![ (Type::Binary, Type::Bool), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "the pattern to match") diff --git a/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs b/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs index 33bbd91545..2bf71eb89b 100644 --- a/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs +++ b/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs @@ -51,6 +51,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs b/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs index d4916bade8..1bba8c65a1 100644 --- a/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs +++ b/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs @@ -22,6 +22,7 @@ impl Command for DecodeHex { Type::List(Box::new(Type::Binary)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs b/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs index 2be8ab5c5b..e0629684d9 100644 --- a/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs +++ b/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs @@ -22,6 +22,7 @@ impl Command for EncodeHex { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs b/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs index 99f50299c2..c51e412644 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs @@ -31,6 +31,7 @@ impl Command for FileSize { .input_output_types(vec![ (Type::Filesize, Type::String), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .required( diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index 7ca011aabd..4a12578c35 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -36,6 +36,7 @@ impl Command for SubCommand { (Type::Filesize, Type::Binary), (Type::Date, Type::Binary), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) // TODO: supply exhaustive examples .rest( diff --git a/crates/nu-command/src/conversions/into/bool.rs b/crates/nu-command/src/conversions/into/bool.rs index e572ae54cb..56de5b1b05 100644 --- a/crates/nu-command/src/conversions/into/bool.rs +++ b/crates/nu-command/src/conversions/into/bool.rs @@ -23,6 +23,7 @@ impl Command for SubCommand { (Type::Bool, Type::Bool), (Type::List(Box::new(Type::Any)), Type::Table(vec![])), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index c826258df6..dd33eb6772 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -69,6 +69,7 @@ impl Command for SubCommand { (Type::String, Type::Date), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Date))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .named( diff --git a/crates/nu-command/src/conversions/into/decimal.rs b/crates/nu-command/src/conversions/into/decimal.rs index 66b03bd2f9..73176c4fbb 100644 --- a/crates/nu-command/src/conversions/into/decimal.rs +++ b/crates/nu-command/src/conversions/into/decimal.rs @@ -21,6 +21,7 @@ impl Command for SubCommand { (Type::String, Type::Number), (Type::Bool, Type::Number), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Number)), diff --git a/crates/nu-command/src/conversions/into/duration.rs b/crates/nu-command/src/conversions/into/duration.rs index c840447d49..66984ac271 100644 --- a/crates/nu-command/src/conversions/into/duration.rs +++ b/crates/nu-command/src/conversions/into/duration.rs @@ -24,7 +24,9 @@ impl Command for SubCommand { (Type::String, Type::String), (Type::Duration, Type::String), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) + .allow_variants_without_examples(true) .named( "convert", SyntaxShape::String, diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 7c6f0d6a51..3f97e86256 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -22,6 +22,7 @@ impl Command for SubCommand { (Type::String, Type::Filesize), (Type::Filesize, Type::Filesize), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::Int)), Type::List(Box::new(Type::Filesize)), diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 50c5019cda..bf4d9c1129 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -39,6 +39,7 @@ impl Command for SubCommand { (Type::Duration, Type::Int), (Type::Filesize, Type::Int), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int)), diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 09b7402e2e..f52d6a2425 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -45,6 +45,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .rest( diff --git a/crates/nu-command/src/hash/generic_digest.rs b/crates/nu-command/src/hash/generic_digest.rs index 5387642c8b..c88d6f2a45 100644 --- a/crates/nu-command/src/hash/generic_digest.rs +++ b/crates/nu-command/src/hash/generic_digest.rs @@ -57,6 +57,7 @@ where (Type::String, Type::String), (Type::String, Type::Binary), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/network/url/encode.rs b/crates/nu-command/src/network/url/encode.rs index 92c33e5d2a..5fb8627d8f 100644 --- a/crates/nu-command/src/network/url/encode.rs +++ b/crates/nu-command/src/network/url/encode.rs @@ -21,6 +21,7 @@ impl Command for SubCommand { (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-command/src/network/url/parse.rs b/crates/nu-command/src/network/url/parse.rs index a83f6087a0..19e5e125ad 100644 --- a/crates/nu-command/src/network/url/parse.rs +++ b/crates/nu-command/src/network/url/parse.rs @@ -20,6 +20,7 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Record(vec![])), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/platform/ansi/strip.rs b/crates/nu-command/src/platform/ansi/strip.rs index c1922c26e8..a0b567c59c 100644 --- a/crates/nu-command/src/platform/ansi/strip.rs +++ b/crates/nu-command/src/platform/ansi/strip.rs @@ -19,6 +19,7 @@ impl Command for SubCommand { (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .rest( "cell path", diff --git a/crates/nu-command/src/strings/encode_decode/decode_base64.rs b/crates/nu-command/src/strings/encode_decode/decode_base64.rs index 19dd55e239..27dcd72ad6 100644 --- a/crates/nu-command/src/strings/encode_decode/decode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/decode_base64.rs @@ -27,6 +27,7 @@ impl Command for DecodeBase64 { Type::List(Box::new(Type::Binary)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/encode_decode/encode_base64.rs b/crates/nu-command/src/strings/encode_decode/encode_base64.rs index 4b5dafea1b..91adaf9a1c 100644 --- a/crates/nu-command/src/strings/encode_decode/encode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/encode_base64.rs @@ -33,6 +33,7 @@ impl Command for EncodeBase64 { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/camel_case.rs b/crates/nu-command/src/strings/str_/case/camel_case.rs index 78cc2dc4e3..982bdc08d0 100644 --- a/crates/nu-command/src/strings/str_/case/camel_case.rs +++ b/crates/nu-command/src/strings/str_/case/camel_case.rs @@ -24,6 +24,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/capitalize.rs b/crates/nu-command/src/strings/str_/case/capitalize.rs index 87ba979d74..21411041bb 100644 --- a/crates/nu-command/src/strings/str_/case/capitalize.rs +++ b/crates/nu-command/src/strings/str_/case/capitalize.rs @@ -22,6 +22,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/downcase.rs b/crates/nu-command/src/strings/str_/case/downcase.rs index 2bd7df1c17..3405b4e532 100644 --- a/crates/nu-command/src/strings/str_/case/downcase.rs +++ b/crates/nu-command/src/strings/str_/case/downcase.rs @@ -22,6 +22,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/kebab_case.rs b/crates/nu-command/src/strings/str_/case/kebab_case.rs index f05fdb3aec..613d1207d2 100644 --- a/crates/nu-command/src/strings/str_/case/kebab_case.rs +++ b/crates/nu-command/src/strings/str_/case/kebab_case.rs @@ -20,6 +20,7 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), diff --git a/crates/nu-command/src/strings/str_/case/pascal_case.rs b/crates/nu-command/src/strings/str_/case/pascal_case.rs index 1220c27832..cdcf6b5e50 100644 --- a/crates/nu-command/src/strings/str_/case/pascal_case.rs +++ b/crates/nu-command/src/strings/str_/case/pascal_case.rs @@ -20,6 +20,7 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), 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 3da90a4288..9423fe4460 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 @@ -23,6 +23,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) 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 cbf7d71a1c..00a5fd4032 100644 --- a/crates/nu-command/src/strings/str_/case/snake_case.rs +++ b/crates/nu-command/src/strings/str_/case/snake_case.rs @@ -23,6 +23,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/title_case.rs b/crates/nu-command/src/strings/str_/case/title_case.rs index 453f914c91..4ed50f5b13 100644 --- a/crates/nu-command/src/strings/str_/case/title_case.rs +++ b/crates/nu-command/src/strings/str_/case/title_case.rs @@ -24,6 +24,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/case/upcase.rs b/crates/nu-command/src/strings/str_/case/upcase.rs index b70adb8d61..9154b0c280 100644 --- a/crates/nu-command/src/strings/str_/case/upcase.rs +++ b/crates/nu-command/src/strings/str_/case/upcase.rs @@ -21,6 +21,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/contains.rs b/crates/nu-command/src/strings/str_/contains.rs index 5cbae64383..eebb9cf959 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -33,6 +33,7 @@ impl Command for SubCommand { (Type::String, Type::Bool), // TODO figure out cell-path type behavior (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))) ]) .vectorizes_over_list(true) @@ -86,14 +87,11 @@ impl Command for SubCommand { result: Some(Value::test_bool(true)), }, Example { - description: "Check if input contains string in a table", - example: " [[ColA ColB]; [test 100]] | str contains 'e' ColA", - result: Some(Value::List { - vals: vec![Value::Record { - cols: vec!["ColA".to_string(), "ColB".to_string()], - vals: vec![Value::test_bool(true), Value::test_int(100)], - span: Span::test_data(), - }], + description: "Check if input contains string in a record", + example: "{ ColA: test, ColB: 100 } | str contains 'e' ColA", + result: Some(Value::Record { + cols: vec!["ColA".to_string(), "ColB".to_string()], + vals: vec![Value::test_bool(true), Value::test_int(100)], span: Span::test_data(), }), }, diff --git a/crates/nu-command/src/strings/str_/distance.rs b/crates/nu-command/src/strings/str_/distance.rs index a6a5510b3b..45981a02b0 100644 --- a/crates/nu-command/src/strings/str_/distance.rs +++ b/crates/nu-command/src/strings/str_/distance.rs @@ -31,6 +31,7 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Int), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .required( "compare-string", @@ -77,7 +78,7 @@ impl Command for SubCommand { result: Some(Value::test_int(1)), }, Example { - description: "Compute edit distance between strings in record and another string, using cell paths", + description: "Compute edit distance between strings in table and another string, using cell paths", example: "[{a: 'nutshell' b: 'numetal'}] | str distance 'nushell' 'a' 'b'", result: Some(Value::List { vals: vec![ @@ -89,6 +90,17 @@ impl Command for SubCommand { ], span: Span::test_data(), }), + }, + Example { + description: "Compute edit distance between strings in record and another string, using cell paths", + example: "{a: 'nutshell' b: 'numetal'} | str distance 'nushell' a b", + result: Some( + Value::Record { + cols: vec!["a".to_string(), "b".to_string()], + vals: vec![Value::test_int(1), Value::test_int(4)], + span: Span::test_data(), + } + ), }] } } diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index 309f084642..a93027a7e6 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -32,6 +32,7 @@ impl Command for SubCommand { (Type::String, Type::Bool), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 4f7e0c3539..51179217a3 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -41,6 +41,7 @@ impl Command for SubCommand { (Type::String, Type::Int), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) // TODO: no test coverage .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/length.rs b/crates/nu-command/src/strings/str_/length.rs index c95294a33a..98a49aea02 100644 --- a/crates/nu-command/src/strings/str_/length.rs +++ b/crates/nu-command/src/strings/str_/length.rs @@ -33,6 +33,7 @@ impl Command for SubCommand { (Type::String, Type::Int), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-command/src/strings/str_/replace.rs b/crates/nu-command/src/strings/str_/replace.rs index 57e72f9b0f..22fa3b4674 100644 --- a/crates/nu-command/src/strings/str_/replace.rs +++ b/crates/nu-command/src/strings/str_/replace.rs @@ -38,6 +38,7 @@ impl Command for SubCommand { (Type::String, Type::String), // TODO: clarify behavior with cellpath-rest argument (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), @@ -135,6 +136,20 @@ impl Command for SubCommand { span: Span::test_data(), }), }, + Example { + description: "Find and replace all occurrences of find string in record", + example: + "{ KeyA: abc, KeyB: abc, KeyC: ads } | str replace -a 'b' 'z' KeyA KeyC", + result: Some(Value::Record { + cols: vec!["KeyA".to_string(), "KeyB".to_string(), "KeyC".to_string()], + vals: vec![ + Value::test_string("azc"), + Value::test_string("abc"), + Value::test_string("ads"), + ], + span: Span::test_data(), + }), + }, Example { description: "Find and replace contents without using the replace parameter as a regular expression", example: r"'dogs_$1_cats' | str replace '\$1' '$2' -n", diff --git a/crates/nu-command/src/strings/str_/reverse.rs b/crates/nu-command/src/strings/str_/reverse.rs index be055f4923..18c9d59c07 100644 --- a/crates/nu-command/src/strings/str_/reverse.rs +++ b/crates/nu-command/src/strings/str_/reverse.rs @@ -23,6 +23,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .allow_variants_without_examples(true) .vectorizes_over_list(true) diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index 9fded97786..72541dc9f1 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -34,6 +34,7 @@ impl Command for SubCommand { (Type::String, Type::Bool), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index e252b19d2f..0058ff9468 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -42,7 +42,12 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("str substring") - .input_output_types(vec![(Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), (Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![ + (Type::String, Type::String), + (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), + (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), + ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/strings/str_/trim/trim_.rs b/crates/nu-command/src/strings/str_/trim/trim_.rs index e2b80ab88d..3b06d2c9f9 100644 --- a/crates/nu-command/src/strings/str_/trim/trim_.rs +++ b/crates/nu-command/src/strings/str_/trim/trim_.rs @@ -42,6 +42,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Record(vec![]), Type::Record(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true)