mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
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.
This commit is contained in:
committed by
GitHub
parent
f8d325dbfe
commit
d9230a76f3
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)),
|
||||
|
@ -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)),
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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(),
|
||||
}),
|
||||
},
|
||||
|
@ -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(),
|
||||
}
|
||||
),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user