mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00: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
28 changed files with 34 additions and 122 deletions
|
@ -24,10 +24,7 @@ impl Command for History {
|
|||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("history")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
(Type::Nothing, Type::Nothing),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.allow_variants_without_examples(true)
|
||||
.switch("clear", "Clears out the history entries", Some('c'))
|
||||
.switch(
|
||||
|
|
|
@ -24,13 +24,10 @@ impl Command for EachWhile {
|
|||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
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::Table(vec![]), Type::List(Box::new(Type::Any))),
|
||||
])
|
||||
)])
|
||||
.required(
|
||||
"closure",
|
||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||
|
|
|
@ -20,10 +20,7 @@ impl Command for Describe {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("describe")
|
||||
.input_output_types(vec![
|
||||
(Type::Any, Type::String),
|
||||
(Type::Any, Type::Record(vec![])),
|
||||
])
|
||||
.input_output_types(vec![(Type::Any, Type::Any)])
|
||||
.switch(
|
||||
"no-collect",
|
||||
"do not collect streams of structured data",
|
||||
|
|
|
@ -30,8 +30,7 @@ impl Command for BytesIndexOf {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build("bytes index-of")
|
||||
.input_output_types(vec![
|
||||
(Type::Binary, Type::Int),
|
||||
(Type::Binary, Type::List(Box::new(Type::Int))),
|
||||
(Type::Binary, Type::Any),
|
||||
// FIXME: this shouldn't be needed, cell paths should work with the two
|
||||
// above
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
|
|
|
@ -22,7 +22,6 @@ impl Command for SubCommand {
|
|||
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
|
||||
(Type::Range, Type::Record(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
(Type::Table(vec![]), Type::Record(vec![])),
|
||||
])
|
||||
.category(Category::Conversions)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ impl Command for Debug {
|
|||
Type::List(Box::new(Type::Any)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::List(Box::new(Type::String))),
|
||||
(Type::Any, Type::String),
|
||||
])
|
||||
.category(Category::Debug)
|
||||
|
|
|
@ -19,10 +19,7 @@ impl Command for ConfigEnv {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name())
|
||||
.category(Category::Env)
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::Nothing),
|
||||
(Type::Nothing, Type::String),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.switch("default", "Print default `env.nu` file instead.", Some('d'))
|
||||
// TODO: Signature narrower than what run actually supports theoretically
|
||||
}
|
||||
|
|
|
@ -19,10 +19,7 @@ impl Command for ConfigNu {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name())
|
||||
.category(Category::Env)
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::Nothing),
|
||||
(Type::Nothing, Type::String),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.switch(
|
||||
"default",
|
||||
"Print default `config.nu` file instead.",
|
||||
|
|
|
@ -16,10 +16,7 @@ impl Command for All {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name())
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::Bool),
|
||||
(Type::Table(vec![]), Type::Bool),
|
||||
])
|
||||
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Bool)])
|
||||
.required(
|
||||
"predicate",
|
||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||
|
|
|
@ -16,10 +16,7 @@ impl Command for Any {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name())
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::Bool),
|
||||
(Type::Table(vec![]), Type::Bool),
|
||||
])
|
||||
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Bool)])
|
||||
.required(
|
||||
"predicate",
|
||||
SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Int])),
|
||||
|
|
|
@ -14,19 +14,10 @@ impl Command for Compact {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("compact")
|
||||
.input_output_types(vec![
|
||||
(
|
||||
.input_output_types(vec![(
|
||||
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(
|
||||
"empty",
|
||||
"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::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Range, Type::List(Box::new(Type::Any))),
|
||||
])
|
||||
.required(
|
||||
|
|
|
@ -30,11 +30,6 @@ impl Command for Find {
|
|||
Type::List(Box::new(Type::Any)),
|
||||
),
|
||||
(Type::String, Type::Any),
|
||||
(
|
||||
// For find -p
|
||||
Type::Table(vec![]),
|
||||
Type::Table(vec![]),
|
||||
),
|
||||
])
|
||||
.named(
|
||||
"regex",
|
||||
|
|
|
@ -17,15 +17,6 @@ impl Command for First {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build("first")
|
||||
.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
|
||||
// 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
|
||||
// the current signature would suffice even when a Table example
|
||||
// exists.
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::Record(vec![])),
|
||||
(Type::List(Box::new(Type::Any)), Type::Table(vec![])),
|
||||
])
|
||||
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Any)])
|
||||
.switch(
|
||||
"to-table",
|
||||
"Return a table with \"groups\" and \"items\" columns",
|
||||
|
|
|
@ -18,10 +18,7 @@ impl Command for Length {
|
|||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("length")
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::Int),
|
||||
(Type::Table(vec![]), Type::Int),
|
||||
])
|
||||
.input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Int)])
|
||||
.category(Category::Filters)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,10 @@ impl Command for Reverse {
|
|||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("reverse")
|
||||
.input_output_types(vec![
|
||||
(
|
||||
.input_output_types(vec![(
|
||||
Type::List(Box::new(Type::Any)),
|
||||
Type::List(Box::new(Type::Any)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
])
|
||||
)])
|
||||
.category(Category::Filters)
|
||||
}
|
||||
|
||||
|
|
|
@ -21,17 +21,10 @@ impl Command for Uniq {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("uniq")
|
||||
.input_output_types(vec![
|
||||
(
|
||||
.input_output_types(vec![(
|
||||
Type::List(Box::new(Type::Any)),
|
||||
Type::List(Box::new(Type::Any)),
|
||||
),
|
||||
(
|
||||
// -c
|
||||
Type::List(Box::new(Type::Any)),
|
||||
Type::Table(vec![]),
|
||||
),
|
||||
])
|
||||
)])
|
||||
.switch(
|
||||
"count",
|
||||
"Return a table containing the distinct input values together with their counts",
|
||||
|
|
|
@ -54,8 +54,7 @@ where
|
|||
Signature::build(self.name())
|
||||
.category(Category::Hash)
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::String),
|
||||
(Type::String, Type::Binary),
|
||||
(Type::String, Type::Any),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
])
|
||||
|
|
|
@ -21,10 +21,7 @@ impl Command for Help {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("help")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::String),
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.rest(
|
||||
"rest",
|
||||
SyntaxShape::String,
|
||||
|
|
|
@ -508,9 +508,7 @@ impl Command for AnsiCommand {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("ansi")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::String),
|
||||
(Type::Nothing, Type::Table(vec![]))])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.optional(
|
||||
"code",
|
||||
SyntaxShape::Any,
|
||||
|
|
|
@ -34,10 +34,7 @@ impl Command for Input {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("input")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::String),
|
||||
(Type::Nothing, Type::Binary),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.allow_variants_without_examples(true)
|
||||
.optional("prompt", SyntaxShape::String, "Prompt to show the user.")
|
||||
.named(
|
||||
|
|
|
@ -39,10 +39,6 @@ impl Command for InputList {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build("input list")
|
||||
.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::Range, Type::Int),
|
||||
])
|
||||
|
|
|
@ -510,10 +510,7 @@ impl Command for ULimit {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
let mut sig = Signature::build("ulimit")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
(Type::Nothing, Type::Nothing),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.switch("soft", "Sets soft resource limit", Some('S'))
|
||||
.switch("hard", "Sets hard resource limit", Some('H'))
|
||||
.switch("all", "Prints all current limits", Some('a'))
|
||||
|
|
|
@ -158,10 +158,7 @@ impl Command for Char {
|
|||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("char")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::String),
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
])
|
||||
.input_output_types(vec![(Type::Nothing, Type::Any)])
|
||||
.optional(
|
||||
"character",
|
||||
SyntaxShape::Any,
|
||||
|
|
|
@ -16,15 +16,10 @@ impl Command for DecodeBase64 {
|
|||
fn signature(&self) -> Signature {
|
||||
Signature::build("decode base64")
|
||||
.input_output_types(vec![
|
||||
(Type::String, Type::String),
|
||||
(Type::String, Type::Binary),
|
||||
(Type::String, Type::Any),
|
||||
(
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::String)),
|
||||
),
|
||||
(
|
||||
Type::List(Box::new(Type::String)),
|
||||
Type::List(Box::new(Type::Binary)),
|
||||
Type::List(Box::new(Type::Any)),
|
||||
),
|
||||
(Type::Table(vec![]), Type::Table(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
|
|
|
@ -29,7 +29,6 @@ impl Command for Griddle {
|
|||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Any)), Type::String),
|
||||
(Type::Record(vec![]), Type::String),
|
||||
(Type::Table(vec![]), Type::String),
|
||||
])
|
||||
.named(
|
||||
"width",
|
||||
|
|
|
@ -62,6 +62,7 @@ impl Type {
|
|||
(Type::Record(this), Type::Record(that)) | (Type::Table(this), Type::Table(that)) => {
|
||||
is_subtype_collection(this, that)
|
||||
}
|
||||
(Type::Table(_), Type::List(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue