From 9db0d6bd34a99805c6da296688aa186778be5a86 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 24 Jul 2023 13:17:30 +0200 Subject: [PATCH] Adjust signatures for cellpath access of tables (#9778) # Description Reallow the commands that take cellpaths as rest parameters to operate on table input data. Went through all commands returned by ``` scope commands | filter { |cmd| $cmd.signatures | values | any {|sig| $sig | any {|$sig| $sig.parameter_type == rest and $sig.syntax_shape == cellpath } } } | get name ``` Only exception to that was `is-empty` that returns a bool. # User-Facing Changes Same table operations as in `0.82` should still be possible Mitigates effects of #9680 --- 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 | 1 + crates/nu-cmd-extra/src/extra/bytes/ends_with.rs | 5 ++++- crates/nu-cmd-extra/src/extra/bytes/length.rs | 2 ++ crates/nu-cmd-extra/src/extra/bytes/reverse.rs | 6 +++++- crates/nu-cmd-extra/src/extra/bytes/starts_with.rs | 6 +++++- .../src/extra/strings/encode_decode/decode_hex.rs | 1 + .../src/extra/strings/encode_decode/encode_hex.rs | 1 + crates/nu-cmd-extra/src/extra/strings/format/filesize.rs | 6 +++++- crates/nu-command/src/conversions/into/binary.rs | 1 + crates/nu-command/src/conversions/into/bool.rs | 2 ++ crates/nu-command/src/conversions/into/string.rs | 1 + crates/nu-command/src/hash/generic_digest.rs | 2 ++ crates/nu-command/src/network/url/encode.rs | 7 ++++++- crates/nu-command/src/network/url/parse.rs | 6 +++++- crates/nu-command/src/platform/ansi/strip.rs | 6 +++++- .../nu-command/src/strings/encode_decode/decode_base64.rs | 1 + .../nu-command/src/strings/encode_decode/encode_base64.rs | 1 + crates/nu-command/src/strings/str_/ends_with.rs | 2 ++ crates/nu-command/src/strings/str_/index_of.rs | 6 +++++- crates/nu-command/src/strings/str_/length.rs | 7 ++++++- crates/nu-command/src/strings/str_/reverse.rs | 2 ++ crates/nu-command/src/strings/str_/starts_with.rs | 6 +++++- 24 files changed, 70 insertions(+), 10 deletions(-) diff --git a/crates/nu-cmd-extra/src/extra/bits/into.rs b/crates/nu-cmd-extra/src/extra/bits/into.rs index 7f8ce49102..1c466f718d 100644 --- a/crates/nu-cmd-extra/src/extra/bits/into.rs +++ b/crates/nu-cmd-extra/src/extra/bits/into.rs @@ -36,6 +36,7 @@ impl Command for BitsInto { (Type::String, Type::String), (Type::Bool, Type::String), (Type::Date, Type::String), + (Type::Table(vec![]), Type::Table(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 00c9a960f4..f5689e78f4 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/add.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/add.rs @@ -36,6 +36,7 @@ impl Command for BytesAdd { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Binary)), ), + (Type::Table(vec![]), Type::Table(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 0e83d27126..f588d9eb95 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/at.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/at.rs @@ -43,6 +43,7 @@ impl Command for BytesAt { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Binary)), ), + (Type::Table(vec![]), Type::Table(vec![])), ]) .vectorizes_over_list(true) .required("range", SyntaxShape::Range, "the range to get bytes") 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 68719caf7e..cb16435aa7 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/ends_with.rs @@ -28,7 +28,10 @@ impl Command for BytesEndsWith { fn signature(&self) -> Signature { Signature::build("bytes ends-with") - .input_output_types(vec![(Type::Binary, Type::Bool)]) + .input_output_types(vec![(Type::Binary, Type::Bool), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "the pattern to match") .rest( "rest", diff --git a/crates/nu-cmd-extra/src/extra/bytes/length.rs b/crates/nu-cmd-extra/src/extra/bytes/length.rs index 3f8caaf721..f672387cb8 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/length.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/length.rs @@ -22,7 +22,9 @@ impl Command for BytesLen { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Int)), ), + (Type::Table(vec![]), Type::Table(vec![])), ]) + .allow_variants_without_examples(true) .vectorizes_over_list(true) .rest( "rest", diff --git a/crates/nu-cmd-extra/src/extra/bytes/reverse.rs b/crates/nu-cmd-extra/src/extra/bytes/reverse.rs index f6e58d72bd..08d0b700cb 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/reverse.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/reverse.rs @@ -17,7 +17,11 @@ impl Command for BytesReverse { fn signature(&self) -> Signature { Signature::build("bytes reverse") - .input_output_types(vec![(Type::Binary, Type::Binary)]) + .input_output_types(vec![ + (Type::Binary, Type::Binary), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .rest( "rest", SyntaxShape::CellPath, 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 7c2c251aae..85e64f1374 100644 --- a/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs +++ b/crates/nu-cmd-extra/src/extra/bytes/starts_with.rs @@ -29,7 +29,11 @@ impl Command for BytesStartsWith { fn signature(&self) -> Signature { Signature::build("bytes starts-with") - .input_output_types(vec![(Type::Binary, Type::Bool)]) + .input_output_types(vec![ + (Type::Binary, Type::Bool), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "the pattern to match") .rest( "rest", 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 61cd1b5d40..d4916bade8 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 @@ -21,6 +21,7 @@ impl Command for DecodeHex { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Binary)), ), + (Type::Table(vec![]), Type::Table(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 13158bcfc7..2be8ab5c5b 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 @@ -21,6 +21,7 @@ impl Command for EncodeHex { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::String)), ), + (Type::Table(vec![]), Type::Table(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 df3b2bb949..99f50299c2 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/filesize.rs @@ -28,7 +28,11 @@ impl Command for FileSize { fn signature(&self) -> Signature { Signature::build("format filesize") - .input_output_types(vec![(Type::Filesize, Type::String)]) + .input_output_types(vec![ + (Type::Filesize, Type::String), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .required( "format value", SyntaxShape::String, diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index fa5ccac20d..7ca011aabd 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -35,6 +35,7 @@ impl Command for SubCommand { (Type::Bool, Type::Binary), (Type::Filesize, Type::Binary), (Type::Date, Type::Binary), + (Type::Table(vec![]), Type::Table(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 1e13e2e4aa..e572ae54cb 100644 --- a/crates/nu-command/src/conversions/into/bool.rs +++ b/crates/nu-command/src/conversions/into/bool.rs @@ -22,7 +22,9 @@ impl Command for SubCommand { (Type::String, Type::Bool), (Type::Bool, Type::Bool), (Type::List(Box::new(Type::Any)), Type::Table(vec![])), + (Type::Table(vec![]), Type::Table(vec![])), ]) + .allow_variants_without_examples(true) .rest( "rest", SyntaxShape::CellPath, diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 699c74f8c8..09b7402e2e 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -44,6 +44,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::String)), ), + (Type::Table(vec![]), Type::Table(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 b56f25c40d..5387642c8b 100644 --- a/crates/nu-command/src/hash/generic_digest.rs +++ b/crates/nu-command/src/hash/generic_digest.rs @@ -56,7 +56,9 @@ where .input_output_types(vec![ (Type::String, Type::String), (Type::String, Type::Binary), + (Type::Table(vec![]), Type::Table(vec![])), ]) + .allow_variants_without_examples(true) .switch( "binary", "Output binary instead of hexadecimal representation", diff --git a/crates/nu-command/src/network/url/encode.rs b/crates/nu-command/src/network/url/encode.rs index 0555fabe44..92c33e5d2a 100644 --- a/crates/nu-command/src/network/url/encode.rs +++ b/crates/nu-command/src/network/url/encode.rs @@ -17,7 +17,12 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("url encode") - .input_output_types(vec![(Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)))]) + .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![])), + ]) + .allow_variants_without_examples(true) .vectorizes_over_list(true) .switch( "all", diff --git a/crates/nu-command/src/network/url/parse.rs b/crates/nu-command/src/network/url/parse.rs index 1676a6c6b1..a83f6087a0 100644 --- a/crates/nu-command/src/network/url/parse.rs +++ b/crates/nu-command/src/network/url/parse.rs @@ -17,7 +17,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("url parse") - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![ + (Type::String, Type::Record(vec![])), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .rest( "rest", SyntaxShape::CellPath, diff --git a/crates/nu-command/src/platform/ansi/strip.rs b/crates/nu-command/src/platform/ansi/strip.rs index 9c38e832a2..c1922c26e8 100644 --- a/crates/nu-command/src/platform/ansi/strip.rs +++ b/crates/nu-command/src/platform/ansi/strip.rs @@ -15,7 +15,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("ansi strip") - .input_output_types(vec![(Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)))]) + .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![])), + ]) .rest( "cell path", SyntaxShape::CellPath, 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 b255d09ece..19dd55e239 100644 --- a/crates/nu-command/src/strings/encode_decode/decode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/decode_base64.rs @@ -26,6 +26,7 @@ impl Command for DecodeBase64 { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Binary)), ), + (Type::Table(vec![]), Type::Table(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 fd06cede59..4b5dafea1b 100644 --- a/crates/nu-command/src/strings/encode_decode/encode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/encode_base64.rs @@ -32,6 +32,7 @@ impl Command for EncodeBase64 { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::String)), ), + (Type::Table(vec![]), Type::Table(vec![])), ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index 97d0b5bfb4..309f084642 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -31,7 +31,9 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Bool), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), + (Type::Table(vec![]), Type::Table(vec![])), ]) + .allow_variants_without_examples(true) .vectorizes_over_list(true) .required("string", SyntaxShape::String, "the string to match") .rest( diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 1bd50bfdae..4f7e0c3539 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -37,7 +37,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("str index-of") - .input_output_types(vec![(Type::String, Type::Int),(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int)))]) + .input_output_types(vec![ + (Type::String, Type::Int), + (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), + (Type::Table(vec![]), Type::Table(vec![])), + ]) .vectorizes_over_list(true) // TODO: no test coverage .allow_variants_without_examples(true) .required("string", SyntaxShape::String, "the string to find in the input") diff --git a/crates/nu-command/src/strings/str_/length.rs b/crates/nu-command/src/strings/str_/length.rs index 8f6c7c6db9..c95294a33a 100644 --- a/crates/nu-command/src/strings/str_/length.rs +++ b/crates/nu-command/src/strings/str_/length.rs @@ -29,7 +29,12 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("str length") - .input_output_types(vec![(Type::String, Type::Int), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int)))]) + .input_output_types(vec![ + (Type::String, Type::Int), + (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), + (Type::Table(vec![]), Type::Table(vec![])), + ]) + .allow_variants_without_examples(true) .vectorizes_over_list(true) .switch( "grapheme-clusters", diff --git a/crates/nu-command/src/strings/str_/reverse.rs b/crates/nu-command/src/strings/str_/reverse.rs index 89209d5028..be055f4923 100644 --- a/crates/nu-command/src/strings/str_/reverse.rs +++ b/crates/nu-command/src/strings/str_/reverse.rs @@ -22,7 +22,9 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), + (Type::Table(vec![]), Type::Table(vec![])), ]) + .allow_variants_without_examples(true) .vectorizes_over_list(true) .rest( "rest", diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index e0fc1e77c7..9fded97786 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -30,7 +30,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("str starts-with") - .input_output_types(vec![(Type::String, Type::Bool),(Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool)))]) + .input_output_types(vec![ + (Type::String, Type::Bool), + (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), + (Type::Table(vec![]), Type::Table(vec![])), + ]) .vectorizes_over_list(true) .allow_variants_without_examples(true) .required("string", SyntaxShape::String, "the string to match")