mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Declare input and output types of commands (#6796)
* Add failing test that list of ints and floats is List<Number> * Start defining subtype relation * Make it possible to declare input and output types for commands - Enforce them in tests * Declare input and output types of commands * Add formatted signatures to `help commands` table * Revert SyntaxShape::Table -> Type::Table change * Revert unnecessary derive(Hash) on SyntaxShape Co-authored-by: JT <547158+jntrnr@users.noreply.github.com>
This commit is contained in:
@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Config, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
|
||||
Value,
|
||||
Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -17,6 +17,7 @@ impl Command for ToCsv {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to csv")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.named(
|
||||
"separator",
|
||||
SyntaxShape::String,
|
||||
|
@ -5,7 +5,7 @@ use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned,
|
||||
SyntaxShape, Value,
|
||||
SyntaxShape, Type, Value,
|
||||
};
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -90,6 +90,7 @@ impl Command for ToHtml {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to html")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.switch("html-color", "change ansi colors to html colors", Some('c'))
|
||||
.switch("no-color", "remove all ansi colors in output", Some('n'))
|
||||
.switch(
|
||||
|
@ -2,7 +2,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::{Call, PathMember};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -15,6 +16,7 @@ impl Command for ToJson {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to json")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.switch("raw", "remove all of the whitespace", Some('r'))
|
||||
.named(
|
||||
"indent",
|
||||
|
@ -3,7 +3,8 @@ use indexmap::map::IndexMap;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
|
||||
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type,
|
||||
Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -16,6 +17,7 @@ impl Command for ToMd {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to md")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.switch(
|
||||
"pretty",
|
||||
"Formats the Markdown table to vertically align items",
|
||||
|
@ -4,7 +4,7 @@ use nu_parser::escape_quote_string;
|
||||
use nu_protocol::ast::{Call, RangeInclusion};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -16,7 +16,9 @@ impl Command for ToNuon {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to nuon").category(Category::Experimental)
|
||||
Signature::build("to nuon")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.category(Category::Experimental)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@ -3,7 +3,7 @@ use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
format_duration, format_filesize_from_conf, Category, Config, Example, IntoPipelineData,
|
||||
PipelineData, ShellError, Signature, Value,
|
||||
PipelineData, ShellError, Signature, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -15,7 +15,9 @@ impl Command for ToText {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to text").category(Category::Formats)
|
||||
Signature::build("to text")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.category(Category::Formats)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@ -13,7 +13,9 @@ impl Command for ToToml {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to toml").category(Category::Formats)
|
||||
Signature::build("to toml")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.category(Category::Formats)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@ -1,7 +1,9 @@
|
||||
use crate::formats::to::delimited::to_delimited_data;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Config, Example, PipelineData, ShellError, Signature, Span, Value};
|
||||
use nu_protocol::{
|
||||
Category, Config, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ToTsv;
|
||||
@ -13,6 +15,7 @@ impl Command for ToTsv {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to tsv")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.switch(
|
||||
"noheaders",
|
||||
"do not output the column names as the first row",
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -13,7 +13,9 @@ impl Command for ToUrl {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to url").category(Category::Formats)
|
||||
Signature::build("to url")
|
||||
.input_output_types(vec![(Type::Table(vec![]), Type::String)])
|
||||
.category(Category::Formats)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Config, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span,
|
||||
Spanned, SyntaxShape, Value,
|
||||
Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||
use std::collections::HashSet;
|
||||
@ -21,6 +21,7 @@ impl Command for ToXml {
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to xml")
|
||||
.input_output_types(vec![(Type::Record(vec![]), Type::String)])
|
||||
.named(
|
||||
"pretty",
|
||||
SyntaxShape::Int,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use nu_protocol::ast::{Call, PathMember};
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value,
|
||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -13,7 +13,9 @@ impl Command for ToYaml {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("to yaml").category(Category::Formats)
|
||||
Signature::build("to yaml")
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.category(Category::Formats)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
|
Reference in New Issue
Block a user