mirror of
https://github.com/nushell/nushell.git
synced 2024-11-28 19:33:47 +01:00
adjust some commansd input_output type (#11436)
# Description 1. Make table to be a subtype of `list<any>`, so some input_output_types of filter commands are unnecessary 2. Change some commands which accept an input type, but generates different output types. In this case, delete duplicate entry, and change relative output type to `<any>` Yeah it makes some commands more permissive, but I think it's better to run into strange issue that why my script runs to failed during parse time. Fixes #11193 # User-Facing Changes NaN # Tests + Formatting NaN # After Submitting NaN
This commit is contained in:
parent
a109283118
commit
e72a4116ec
@ -24,10 +24,7 @@ impl Command for History {
|
|||||||
|
|
||||||
fn signature(&self) -> nu_protocol::Signature {
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
Signature::build("history")
|
Signature::build("history")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::Table(vec![])),
|
|
||||||
(Type::Nothing, Type::Nothing),
|
|
||||||
])
|
|
||||||
.allow_variants_without_examples(true)
|
.allow_variants_without_examples(true)
|
||||||
.switch("clear", "Clears out the history entries", Some('c'))
|
.switch("clear", "Clears out the history entries", Some('c'))
|
||||||
.switch(
|
.switch(
|
||||||
|
@ -24,13 +24,10 @@ impl Command for EachWhile {
|
|||||||
|
|
||||||
fn signature(&self) -> nu_protocol::Signature {
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(
|
||||||
(
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
)])
|
||||||
),
|
|
||||||
(Type::Table(vec![]), Type::List(Box::new(Type::Any))),
|
|
||||||
])
|
|
||||||
.required(
|
.required(
|
||||||
"closure",
|
"closure",
|
||||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||||
|
@ -20,10 +20,7 @@ impl Command for Describe {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("describe")
|
Signature::build("describe")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Any, Type::Any)])
|
||||||
(Type::Any, Type::String),
|
|
||||||
(Type::Any, Type::Record(vec![])),
|
|
||||||
])
|
|
||||||
.switch(
|
.switch(
|
||||||
"no-collect",
|
"no-collect",
|
||||||
"do not collect streams of structured data",
|
"do not collect streams of structured data",
|
||||||
|
@ -30,8 +30,7 @@ impl Command for BytesIndexOf {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("bytes index-of")
|
Signature::build("bytes index-of")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::Binary, Type::Int),
|
(Type::Binary, Type::Any),
|
||||||
(Type::Binary, Type::List(Box::new(Type::Int))),
|
|
||||||
// FIXME: this shouldn't be needed, cell paths should work with the two
|
// FIXME: this shouldn't be needed, cell paths should work with the two
|
||||||
// above
|
// above
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
(Type::Table(vec![]), Type::Table(vec![])),
|
||||||
|
@ -22,7 +22,6 @@ impl Command for SubCommand {
|
|||||||
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
|
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
|
||||||
(Type::Range, Type::Record(vec![])),
|
(Type::Range, Type::Record(vec![])),
|
||||||
(Type::Record(vec![]), Type::Record(vec![])),
|
(Type::Record(vec![]), Type::Record(vec![])),
|
||||||
(Type::Table(vec![]), Type::Record(vec![])),
|
|
||||||
])
|
])
|
||||||
.category(Category::Conversions)
|
.category(Category::Conversions)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ impl Command for Debug {
|
|||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::String)),
|
Type::List(Box::new(Type::String)),
|
||||||
),
|
),
|
||||||
(Type::Table(vec![]), Type::List(Box::new(Type::String))),
|
|
||||||
(Type::Any, Type::String),
|
(Type::Any, Type::String),
|
||||||
])
|
])
|
||||||
.category(Category::Debug)
|
.category(Category::Debug)
|
||||||
|
@ -19,10 +19,7 @@ impl Command for ConfigEnv {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.category(Category::Env)
|
.category(Category::Env)
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::Nothing),
|
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
])
|
|
||||||
.switch("default", "Print default `env.nu` file instead.", Some('d'))
|
.switch("default", "Print default `env.nu` file instead.", Some('d'))
|
||||||
// TODO: Signature narrower than what run actually supports theoretically
|
// TODO: Signature narrower than what run actually supports theoretically
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,7 @@ impl Command for ConfigNu {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.category(Category::Env)
|
.category(Category::Env)
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::Nothing),
|
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
])
|
|
||||||
.switch(
|
.switch(
|
||||||
"default",
|
"default",
|
||||||
"Print default `config.nu` file instead.",
|
"Print default `config.nu` file instead.",
|
||||||
|
@ -16,10 +16,7 @@ impl Command for All {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Bool)])
|
||||||
(Type::List(Box::new(Type::Any)), Type::Bool),
|
|
||||||
(Type::Table(vec![]), Type::Bool),
|
|
||||||
])
|
|
||||||
.required(
|
.required(
|
||||||
"predicate",
|
"predicate",
|
||||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||||
|
@ -16,10 +16,7 @@ impl Command for Any {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Bool)])
|
||||||
(Type::List(Box::new(Type::Any)), Type::Bool),
|
|
||||||
(Type::Table(vec![]), Type::Bool),
|
|
||||||
])
|
|
||||||
.required(
|
.required(
|
||||||
"predicate",
|
"predicate",
|
||||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||||
|
@ -14,19 +14,10 @@ impl Command for Compact {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("compact")
|
Signature::build("compact")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(
|
||||||
(
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
)])
|
||||||
),
|
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
|
||||||
(
|
|
||||||
// TODO: Should table be a subtype of List<Any>? If so then this
|
|
||||||
// entry would be unnecessary.
|
|
||||||
Type::Table(vec![]),
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.switch(
|
.switch(
|
||||||
"empty",
|
"empty",
|
||||||
"also compact empty items like \"\", {}, and []",
|
"also compact empty items like \"\", {}, and []",
|
||||||
|
@ -31,7 +31,6 @@ a variable. On the other hand, the "row condition" syntax is not supported."#
|
|||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
),
|
),
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
|
||||||
(Type::Range, Type::List(Box::new(Type::Any))),
|
(Type::Range, Type::List(Box::new(Type::Any))),
|
||||||
])
|
])
|
||||||
.required(
|
.required(
|
||||||
|
@ -30,11 +30,6 @@ impl Command for Find {
|
|||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
),
|
),
|
||||||
(Type::String, Type::Any),
|
(Type::String, Type::Any),
|
||||||
(
|
|
||||||
// For find -p
|
|
||||||
Type::Table(vec![]),
|
|
||||||
Type::Table(vec![]),
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
.named(
|
.named(
|
||||||
"regex",
|
"regex",
|
||||||
|
@ -17,15 +17,6 @@ impl Command for First {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("first")
|
Signature::build("first")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(
|
|
||||||
// TODO: This variant duplicates the functionality of
|
|
||||||
// `take`. See #6611, #6611, #6893
|
|
||||||
// TODO: This is too permissive; if we could express this
|
|
||||||
// using a type parameter style it would be List<T> ->
|
|
||||||
// List<T>.
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
// TODO: This is too permissive; if we could express this
|
// TODO: This is too permissive; if we could express this
|
||||||
// using a type parameter it would be List<T> -> T.
|
// using a type parameter it would be List<T> -> T.
|
||||||
|
@ -22,10 +22,7 @@ impl Command for GroupBy {
|
|||||||
// example. Perhaps Table should be a subtype of List, in which case
|
// example. Perhaps Table should be a subtype of List, in which case
|
||||||
// the current signature would suffice even when a Table example
|
// the current signature would suffice even when a Table example
|
||||||
// exists.
|
// exists.
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Any)])
|
||||||
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
|
|
||||||
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
|
|
||||||
])
|
|
||||||
.switch(
|
.switch(
|
||||||
"to-table",
|
"to-table",
|
||||||
"Return a table with \"groups\" and \"items\" columns",
|
"Return a table with \"groups\" and \"items\" columns",
|
||||||
|
@ -18,10 +18,7 @@ impl Command for Length {
|
|||||||
|
|
||||||
fn signature(&self) -> nu_protocol::Signature {
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
Signature::build("length")
|
Signature::build("length")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Int)])
|
||||||
(Type::List(Box::new(Type::Any)), Type::Int),
|
|
||||||
(Type::Table(vec![]), Type::Int),
|
|
||||||
])
|
|
||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,13 +15,10 @@ impl Command for Reverse {
|
|||||||
|
|
||||||
fn signature(&self) -> nu_protocol::Signature {
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
Signature::build("reverse")
|
Signature::build("reverse")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(
|
||||||
(
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
)])
|
||||||
),
|
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
|
||||||
])
|
|
||||||
.category(Category::Filters)
|
.category(Category::Filters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,10 @@ impl Command for Uniq {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("uniq")
|
Signature::build("uniq")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(
|
||||||
(
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
Type::List(Box::new(Type::Any)),
|
||||||
Type::List(Box::new(Type::Any)),
|
)])
|
||||||
),
|
|
||||||
(
|
|
||||||
// -c
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
Type::Table(vec![]),
|
|
||||||
),
|
|
||||||
])
|
|
||||||
.switch(
|
.switch(
|
||||||
"count",
|
"count",
|
||||||
"Return a table containing the distinct input values together with their counts",
|
"Return a table containing the distinct input values together with their counts",
|
||||||
|
@ -54,8 +54,7 @@ where
|
|||||||
Signature::build(self.name())
|
Signature::build(self.name())
|
||||||
.category(Category::Hash)
|
.category(Category::Hash)
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::String, Type::String),
|
(Type::String, Type::Any),
|
||||||
(Type::String, Type::Binary),
|
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
(Type::Table(vec![]), Type::Table(vec![])),
|
||||||
(Type::Record(vec![]), Type::Record(vec![])),
|
(Type::Record(vec![]), Type::Record(vec![])),
|
||||||
])
|
])
|
||||||
|
@ -21,10 +21,7 @@ impl Command for Help {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("help")
|
Signature::build("help")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
(Type::Nothing, Type::Table(vec![])),
|
|
||||||
])
|
|
||||||
.rest(
|
.rest(
|
||||||
"rest",
|
"rest",
|
||||||
SyntaxShape::String,
|
SyntaxShape::String,
|
||||||
|
@ -508,9 +508,7 @@ impl Command for AnsiCommand {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("ansi")
|
Signature::build("ansi")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
(Type::Nothing, Type::Table(vec![]))])
|
|
||||||
.optional(
|
.optional(
|
||||||
"code",
|
"code",
|
||||||
SyntaxShape::Any,
|
SyntaxShape::Any,
|
||||||
|
@ -34,10 +34,7 @@ impl Command for Input {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("input")
|
Signature::build("input")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
(Type::Nothing, Type::Binary),
|
|
||||||
])
|
|
||||||
.allow_variants_without_examples(true)
|
.allow_variants_without_examples(true)
|
||||||
.optional("prompt", SyntaxShape::String, "Prompt to show the user.")
|
.optional("prompt", SyntaxShape::String, "Prompt to show the user.")
|
||||||
.named(
|
.named(
|
||||||
|
@ -39,10 +39,6 @@ impl Command for InputList {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("input list")
|
Signature::build("input list")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
Type::List(Box::new(Type::Any)),
|
|
||||||
),
|
|
||||||
(Type::List(Box::new(Type::Any)), Type::Any),
|
(Type::List(Box::new(Type::Any)), Type::Any),
|
||||||
(Type::Range, Type::Int),
|
(Type::Range, Type::Int),
|
||||||
])
|
])
|
||||||
|
@ -510,10 +510,7 @@ impl Command for ULimit {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
let mut sig = Signature::build("ulimit")
|
let mut sig = Signature::build("ulimit")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::Table(vec![])),
|
|
||||||
(Type::Nothing, Type::Nothing),
|
|
||||||
])
|
|
||||||
.switch("soft", "Sets soft resource limit", Some('S'))
|
.switch("soft", "Sets soft resource limit", Some('S'))
|
||||||
.switch("hard", "Sets hard resource limit", Some('H'))
|
.switch("hard", "Sets hard resource limit", Some('H'))
|
||||||
.switch("all", "Prints all current limits", Some('a'))
|
.switch("all", "Prints all current limits", Some('a'))
|
||||||
|
@ -158,10 +158,7 @@ impl Command for Char {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("char")
|
Signature::build("char")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||||
(Type::Nothing, Type::String),
|
|
||||||
(Type::Nothing, Type::Table(vec![])),
|
|
||||||
])
|
|
||||||
.optional(
|
.optional(
|
||||||
"character",
|
"character",
|
||||||
SyntaxShape::Any,
|
SyntaxShape::Any,
|
||||||
|
@ -16,15 +16,10 @@ impl Command for DecodeBase64 {
|
|||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("decode base64")
|
Signature::build("decode base64")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::String, Type::String),
|
(Type::String, Type::Any),
|
||||||
(Type::String, Type::Binary),
|
|
||||||
(
|
(
|
||||||
Type::List(Box::new(Type::String)),
|
Type::List(Box::new(Type::String)),
|
||||||
Type::List(Box::new(Type::String)),
|
Type::List(Box::new(Type::Any)),
|
||||||
),
|
|
||||||
(
|
|
||||||
Type::List(Box::new(Type::String)),
|
|
||||||
Type::List(Box::new(Type::Binary)),
|
|
||||||
),
|
),
|
||||||
(Type::Table(vec![]), Type::Table(vec![])),
|
(Type::Table(vec![]), Type::Table(vec![])),
|
||||||
(Type::Record(vec![]), Type::Record(vec![])),
|
(Type::Record(vec![]), Type::Record(vec![])),
|
||||||
|
@ -29,7 +29,6 @@ impl Command for Griddle {
|
|||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::List(Box::new(Type::Any)), Type::String),
|
(Type::List(Box::new(Type::Any)), Type::String),
|
||||||
(Type::Record(vec![]), Type::String),
|
(Type::Record(vec![]), Type::String),
|
||||||
(Type::Table(vec![]), Type::String),
|
|
||||||
])
|
])
|
||||||
.named(
|
.named(
|
||||||
"width",
|
"width",
|
||||||
|
@ -62,6 +62,7 @@ impl Type {
|
|||||||
(Type::Record(this), Type::Record(that)) | (Type::Table(this), Type::Table(that)) => {
|
(Type::Record(this), Type::Record(that)) | (Type::Table(this), Type::Table(that)) => {
|
||||||
is_subtype_collection(this, that)
|
is_subtype_collection(this, that)
|
||||||
}
|
}
|
||||||
|
(Type::Table(_), Type::List(_)) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user