Add more input/output type annotations (#7532)

This commit is contained in:
Stefan Holderbach 2022-12-21 20:20:46 +01:00 committed by GitHub
parent d27263af97
commit 4e1f94026c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 324 additions and 186 deletions

View File

@ -1,6 +1,6 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type, Value};
use reedline::Highlighter; use reedline::Highlighter;
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,9 @@ impl Command for NuHighlight {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("nu-highlight").category(Category::Strings) Signature::build("nu-highlight")
.category(Category::Strings)
.input_output_types(vec![(Type::String, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -15,6 +16,7 @@ impl Command for Print {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("print") Signature::build("print")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.rest("rest", SyntaxShape::Any, "the values to print") .rest("rest", SyntaxShape::Any, "the values to print")
.switch( .switch(
"no-newline", "no-newline",

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Bits {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("bits").category(Category::Bits) Signature::build("bits")
.category(Category::Bits)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -41,15 +43,3 @@ impl Command for Bits {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
#[cfg(test)]
mod test {
use crate::Bits;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Bits {})
}
}

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Bytes {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("bytes").category(Category::Bytes) Signature::build("bytes")
.category(Category::Bytes)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -41,15 +43,3 @@ impl Command for Bytes {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
#[cfg(test)]
mod test {
use crate::Bytes;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Bytes {})
}
}

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Into {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("into").category(Category::Conversions) Signature::build("into")
.category(Category::Conversions)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -41,15 +43,3 @@ impl Command for Into {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Into {})
}
}

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -15,6 +15,7 @@ impl Command for ErrorMake {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("error make") Signature::build("error make")
.input_output_types(vec![(Type::Nothing, Type::Error)])
.required("error_struct", SyntaxShape::Record, "the error to create") .required("error_struct", SyntaxShape::Record, "the error to create")
.switch( .switch(
"unspanned", "unspanned",

View File

@ -2,7 +2,7 @@ use nu_engine::{eval_block, eval_expression, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Block, Command, EngineState, Stack}; use nu_protocol::engine::{Block, Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, ListStream, PipelineData, ShellError, Signature, SyntaxShape, Value, Category, Example, ListStream, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -19,6 +19,8 @@ impl Command for For {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("for") Signature::build("for")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required( .required(
"var_name", "var_name",
SyntaxShape::VarWithOptType, SyntaxShape::VarWithOptType,

View File

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -17,7 +17,10 @@ impl Command for HelpOperators {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("help operators").category(Category::Core) Signature::build("help operators")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.allow_variants_without_examples(true)
} }
fn run( fn run(

View File

@ -2,7 +2,7 @@ use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Block, Command, EngineState, Stack}; use nu_protocol::engine::{Block, Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -19,6 +19,8 @@ impl Command for Loop {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("loop") Signature::build("loop")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required("block", SyntaxShape::Block, "block to loop") .required("block", SyntaxShape::Block, "block to loop")
.category(Category::Core) .category(Category::Core)
} }

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Overlay {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("overlay").category(Category::Core) Signature::build("overlay")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -50,15 +52,3 @@ impl Command for Overlay {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Overlay {})
}
}

View File

@ -1,7 +1,9 @@
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
};
#[derive(Clone)] #[derive(Clone)]
pub struct OverlayHide; pub struct OverlayHide;
@ -17,6 +19,7 @@ impl Command for OverlayHide {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("overlay hide") Signature::build("overlay hide")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.optional("name", SyntaxShape::String, "Overlay to hide") .optional("name", SyntaxShape::String, "Overlay to hide")
.switch( .switch(
"keep-custom", "keep-custom",

View File

@ -1,7 +1,7 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -17,7 +17,9 @@ impl Command for OverlayList {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("overlay list").category(Category::Core) Signature::build("overlay list")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::List(Box::new(Type::String)))])
} }
fn extra_usage(&self) -> &str { fn extra_usage(&self) -> &str {

View File

@ -1,7 +1,9 @@
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
};
#[derive(Clone)] #[derive(Clone)]
pub struct OverlayNew; pub struct OverlayNew;
@ -17,6 +19,8 @@ impl Command for OverlayNew {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("overlay new") Signature::build("overlay new")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required("name", SyntaxShape::String, "Name of the overlay") .required("name", SyntaxShape::String, "Name of the overlay")
// TODO: // TODO:
// .switch( // .switch(

View File

@ -3,7 +3,7 @@ use nu_parser::trim_quotes_str;
use nu_protocol::ast::{Call, Expr}; use nu_protocol::ast::{Call, Expr};
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
use std::path::Path; use std::path::Path;
@ -22,6 +22,8 @@ impl Command for OverlayUse {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("overlay use") Signature::build("overlay use")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required( .required(
"name", "name",
SyntaxShape::String, SyntaxShape::String,

View File

@ -1,7 +1,9 @@
use nu_engine::{eval_block, eval_expression, CallExt}; use nu_engine::{eval_block, eval_expression, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Block, Command, EngineState, Stack}; use nu_protocol::engine::{Block, Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
#[derive(Clone)] #[derive(Clone)]
pub struct While; pub struct While;
@ -17,6 +19,8 @@ impl Command for While {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("while") Signature::build("while")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required("cond", SyntaxShape::Expression, "condition to check") .required("cond", SyntaxShape::Expression, "condition to check")
.required( .required(
"block", "block",

View File

@ -20,6 +20,9 @@ impl Command for IntoSqliteDb {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("into sqlite") Signature::build("into sqlite")
.input_output_types(vec![(Type::Any, Type::Nothing)])
.allow_variants_without_examples(true)
// TODO: narrow disallowed types
.required( .required(
"file_name", "file_name",
SyntaxShape::String, SyntaxShape::String,

View File

@ -18,6 +18,7 @@ impl Command for QueryDb {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.input_output_types(vec![(Type::Any, Type::Any)])
.required( .required(
"SQL", "SQL",
SyntaxShape::String, SyntaxShape::String,

View File

@ -16,6 +16,7 @@ impl Command for SchemaDb {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.input_output_types(vec![(Type::Any, Type::Any)])
.input_type(Type::Any) .input_type(Type::Any)
.output_type(Type::Any) .output_type(Type::Any)
.category(Category::Custom("database".into())) .category(Category::Custom("database".into()))

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, ShellError, Signature, Value, Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Date {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("date").category(Category::Date) Signature::build("date")
.category(Category::Date)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_engine::{eval_block, CallExt}; use nu_engine::{eval_block, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -14,6 +14,7 @@ impl Command for Source {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("source") Signature::build("source")
.input_output_types(vec![(Type::Any, Type::Any)])
.required( .required(
"filename", "filename",
SyntaxShape::Filepath, SyntaxShape::Filepath,

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for ConfigMeta {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Env) Signature::build(self.name())
.category(Category::Env)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_strings;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Type,
}; };
use crate::ExternalCommand; use crate::ExternalCommand;
@ -18,7 +18,10 @@ impl Command for ConfigEnv {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Env) Signature::build(self.name())
.category(Category::Env)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
// TODO: Signature narrower than what run actually supports theoretically
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_strings;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Type,
}; };
use crate::ExternalCommand; use crate::ExternalCommand;
@ -18,7 +18,10 @@ impl Command for ConfigNu {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Env) Signature::build(self.name())
.category(Category::Env)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
// TODO: Signature narrower than what run actually supports theoretically
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_string;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -18,7 +18,9 @@ impl Command for Env {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("env").category(Category::Env) Signature::build("env")
.category(Category::Env)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
} }
fn run( fn run(

View File

@ -2,7 +2,7 @@ use nu_engine::{eval_expression_with_input, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -19,6 +19,8 @@ impl Command for LetEnv {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("let-env") Signature::build("let-env")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
.required("var_name", SyntaxShape::String, "variable name") .required("var_name", SyntaxShape::String, "variable name")
.required( .required(
"initial_value", "initial_value",

View File

@ -1,7 +1,9 @@
use nu_engine::{current_dir, CallExt}; use nu_engine::{current_dir, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
#[derive(Clone)] #[derive(Clone)]
pub struct LoadEnv; pub struct LoadEnv;
@ -17,6 +19,8 @@ impl Command for LoadEnv {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("load-env") Signature::build("load-env")
.input_output_types(vec![(Type::Record(vec![]), Type::Nothing)])
.allow_variants_without_examples(true)
.optional( .optional(
"update", "update",
SyntaxShape::Record, SyntaxShape::Record,

View File

@ -4,7 +4,7 @@ use nu_engine::{eval_block, find_in_dirs_env, redirect_env, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
/// Source a file for environment variables. /// Source a file for environment variables.
@ -18,6 +18,7 @@ impl Command for SourceEnv {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("source-env") Signature::build("source-env")
.input_output_types(vec![(Type::Any, Type::Any)])
.required( .required(
"filename", "filename",
SyntaxShape::String, // type is string to avoid automatically canonicalizing the path SyntaxShape::String, // type is string to avoid automatically canonicalizing the path

View File

@ -1,7 +1,9 @@
use is_root::is_root; use is_root::is_root;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Span, Value}; use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, Signature, Span, Type, Value,
};
#[derive(Clone)] #[derive(Clone)]
pub struct IsAdmin; pub struct IsAdmin;
@ -16,7 +18,10 @@ impl Command for IsAdmin {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("is-admin").category(Category::Core) Signature::build("is-admin")
.category(Category::Core)
.input_output_types(vec![(Type::Nothing, Type::Bool)])
.allow_variants_without_examples(true)
} }
fn search_terms(&self) -> Vec<&str> { fn search_terms(&self) -> Vec<&str> {

View File

@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -21,6 +21,7 @@ impl Command for ViewSource {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("view-source") Signature::build("view-source")
.input_output_types(vec![(Type::Nothing, Type::String)])
.required("item", SyntaxShape::Any, "name or block to view") .required("item", SyntaxShape::Any, "name or block to view")
.category(Category::Core) .category(Category::Core)
} }

View File

@ -8,7 +8,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Closure, Command, EngineState, Stack, StateWorkingSet}; use nu_protocol::engine::{Closure, Command, EngineState, Stack, StateWorkingSet};
use nu_protocol::{ use nu_protocol::{
format_error, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, format_error, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature,
Spanned, SyntaxShape, Value, Spanned, SyntaxShape, Type, Value,
}; };
// durations chosen mostly arbitrarily // durations chosen mostly arbitrarily
@ -33,6 +33,7 @@ impl Command for Watch {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("watch") Signature::build("watch")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.required("path", SyntaxShape::Filepath, "the path to watch. Can be a file or directory") .required("path", SyntaxShape::Filepath, "the path to watch. Can be a file or directory")
.required("closure", .required("closure",
SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])), SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])),

View File

@ -1,7 +1,7 @@
use nu_engine::get_full_help; use nu_engine::get_full_help;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct Roll; pub struct Roll;
@ -16,7 +16,9 @@ impl Command for Roll {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Filters) Signature::build(self.name())
.category(Category::Filters)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_engine::get_full_help; use nu_engine::get_full_help;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct From; pub struct From;
@ -16,7 +16,9 @@ impl Command for From {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("from").category(Category::Formats) Signature::build("from")
.category(Category::Formats)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn run( fn run(

View File

@ -51,7 +51,9 @@ impl Command for FromYml {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("from yml").category(Category::Formats) Signature::build("from yml")
.input_output_types(vec![(Type::String, Type::Any)])
.category(Category::Formats)
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_engine::get_full_help; use nu_engine::get_full_help;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct To; pub struct To;
@ -16,7 +16,9 @@ impl Command for To {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("to").category(Category::Formats) Signature::build("to")
.category(Category::Formats)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn run( fn run(

View File

@ -1,7 +1,7 @@
use nu_engine::get_full_help; use nu_engine::get_full_help;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct Hash; pub struct Hash;
@ -12,7 +12,9 @@ impl Command for Hash {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("hash").category(Category::Hash) Signature::build("hash")
.category(Category::Hash)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for MathCommand {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("math").category(Category::Math) Signature::build("math")
.category(Category::Math)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, HistoryFileFormat, IntoInterruptiblePipelineData, PipelineData, ShellError, Category, Example, HistoryFileFormat, IntoInterruptiblePipelineData, PipelineData, ShellError,
Signature, Span, Value, Signature, Span, Type, Value,
}; };
use reedline::{ use reedline::{
FileBackedHistory, History as ReedlineHistory, HistoryItem, SearchDirection, SearchQuery, FileBackedHistory, History as ReedlineHistory, HistoryItem, SearchDirection, SearchQuery,
@ -23,6 +23,11 @@ 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![
(Type::Nothing, Type::Table(vec![])),
(Type::Nothing, Type::Nothing),
])
.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(
"long", "long",

View File

@ -1,6 +1,6 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Value}; use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct HistorySession; pub struct HistorySession;
@ -15,7 +15,9 @@ impl Command for HistorySession {
} }
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("history session").category(Category::Misc) Signature::build("history session")
.category(Category::Misc)
.input_output_types(vec![(Type::Nothing, Type::Int)])
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View File

@ -4,7 +4,7 @@ use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, SyntaxShape,
Value, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -17,6 +17,8 @@ impl Command for Tutor {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("tutor") Signature::build("tutor")
.input_output_types(vec![(Type::Nothing, Type::String)])
.allow_variants_without_examples(true)
.optional( .optional(
"search", "search",
SyntaxShape::String, SyntaxShape::String,

View File

@ -7,7 +7,7 @@ use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::RawStream; use nu_protocol::RawStream;
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use reqwest::blocking::Response; use reqwest::blocking::Response;
@ -29,6 +29,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("fetch") Signature::build("fetch")
.input_output_types(vec![(Type::Nothing, Type::Any)])
.required( .required(
"URL", "URL",
SyntaxShape::String, SyntaxShape::String,

View File

@ -5,7 +5,7 @@ use nu_protocol::IntoPipelineData;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener}; use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4, TcpListener};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -18,6 +18,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("port") Signature::build("port")
.input_output_types(vec![(Type::Nothing, Type::Int)])
.optional( .optional(
"start", "start",
SyntaxShape::Int, SyntaxShape::Int,

View File

@ -10,7 +10,7 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use std::collections::HashMap; use std::collections::HashMap;
use std::io::BufReader; use std::io::BufReader;
@ -25,6 +25,7 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("post") Signature::build("post")
.input_output_types(vec![(Type::Nothing, Type::Any)])
.required("path", SyntaxShape::String, "the URL to post to") .required("path", SyntaxShape::String, "the URL to post to")
.required("body", SyntaxShape::Any, "the contents of the post body") .required("body", SyntaxShape::Any, "the contents of the post body")
.named( .named(

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
IntoPipelineData, PipelineData, Signature, Value, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,7 @@ impl Command for PathCommand {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("path") Signature::build("path").input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
}; };
use std::process::Command as CommandSys; use std::process::Command as CommandSys;
@ -18,7 +18,9 @@ impl Command for Clear {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("clear").category(Category::Platform) Signature::build("clear")
.category(Category::Platform)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
} }
fn run( fn run(

View File

@ -5,7 +5,7 @@ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Spanned,
SyntaxShape, Value, SyntaxShape, Type, Value,
}; };
use serde::Deserialize; use serde::Deserialize;
use std::path::PathBuf; use std::path::PathBuf;
@ -43,6 +43,8 @@ impl Command for Du {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("du") Signature::build("du")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.allow_variants_without_examples(true)
.optional("path", SyntaxShape::GlobPattern, "starting directory") .optional("path", SyntaxShape::GlobPattern, "starting directory")
.switch( .switch(
"all", "all",

View File

@ -3,7 +3,8 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Type,
Value,
}; };
use std::io::{Read, Write}; use std::io::{Read, Write};
@ -25,6 +26,11 @@ impl Command for Input {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("input") Signature::build("input")
.input_output_types(vec![
(Type::Nothing, Type::String),
(Type::Nothing, Type::Binary),
])
.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(
"bytes-until", "bytes-until",

View File

@ -3,7 +3,7 @@ use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ast::Call, span}; use nu_protocol::{ast::Call, span};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
Signature, Spanned, SyntaxShape, Value, Signature, Spanned, SyntaxShape, Type, Value,
}; };
use std::process::{Command as CommandSys, Stdio}; use std::process::{Command as CommandSys, Stdio};
@ -21,6 +21,8 @@ impl Command for Kill {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
let signature = Signature::build("kill") let signature = Signature::build("kill")
.input_output_types(vec![(Type::Nothing, Type::Any)])
.allow_variants_without_examples(true)
.required( .required(
"pid", "pid",
SyntaxShape::Int, SyntaxShape::Int,

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Keybindings {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Platform) Signature::build(self.name())
.category(Category::Platform)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, Signature, Value, Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
use reedline::get_reedline_default_keybindings; use reedline::get_reedline_default_keybindings;
@ -14,7 +14,9 @@ impl Command for KeybindingsDefault {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Platform) Signature::build(self.name())
.category(Category::Platform)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, Signature, Span, Value, Category, Example, IntoPipelineData, PipelineData, Signature, Span, Type, Value,
}; };
use reedline::{ use reedline::{
get_reedline_edit_commands, get_reedline_keybinding_modifiers, get_reedline_keycodes, get_reedline_edit_commands, get_reedline_keybinding_modifiers, get_reedline_keycodes,
@ -18,6 +18,7 @@ impl Command for KeybindingsList {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.switch("modifiers", "list of modifiers", Some('m')) .switch("modifiers", "list of modifiers", Some('m'))
.switch("keycodes", "list of keycodes", Some('k')) .switch("keycodes", "list of keycodes", Some('k'))
.switch("modes", "list of edit modes", Some('o')) .switch("modes", "list of edit modes", Some('o'))

View File

@ -3,7 +3,7 @@ use crossterm::{event::Event, event::KeyCode, event::KeyEvent, terminal};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use std::io::{stdout, Write}; use std::io::{stdout, Write};
@ -20,7 +20,10 @@ impl Command for KeybindingsListen {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Platform) Signature::build(self.name())
.category(Category::Platform)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.allow_variants_without_examples(true)
} }
fn run( fn run(

View File

@ -1,6 +1,8 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Span, Value}; use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, Signature, Span, Type, Value,
};
use terminal_size::{terminal_size, Height, Width}; use terminal_size::{terminal_size, Height, Width};
#[derive(Clone)] #[derive(Clone)]
@ -16,7 +18,15 @@ impl Command for TermSize {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("term size").category(Category::Platform) Signature::build("term size")
.category(Category::Platform)
.input_output_types(vec![(
Type::Nothing,
Type::Record(vec![
("columns".into(), Type::Int),
("rows".into(), Type::Int),
]),
)])
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
use rand::prelude::{thread_rng, Rng}; use rand::prelude::{thread_rng, Rng};
@ -16,6 +16,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random bool") Signature::build("random bool")
.input_output_types(vec![(Type::Nothing, Type::Bool)])
.allow_variants_without_examples(true)
.named( .named(
"bias", "bias",
SyntaxShape::Number, SyntaxShape::Number,

View File

@ -1,7 +1,9 @@
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
use rand::{ use rand::{
distributions::{Alphanumeric, Distribution}, distributions::{Alphanumeric, Distribution},
thread_rng, thread_rng,
@ -19,6 +21,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random chars") Signature::build("random chars")
.input_output_types(vec![(Type::Nothing, Type::String)])
.allow_variants_without_examples(true)
.named("length", SyntaxShape::Int, "Number of chars", Some('l')) .named("length", SyntaxShape::Int, "Number of chars", Some('l'))
.category(Category::Random) .category(Category::Random)
} }

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, Range, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, Range, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use rand::prelude::{thread_rng, Rng}; use rand::prelude::{thread_rng, Rng};
use std::cmp::Ordering; use std::cmp::Ordering;
@ -17,6 +17,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random decimal") Signature::build("random decimal")
.input_output_types(vec![(Type::Nothing, Type::Float)])
.allow_variants_without_examples(true)
.optional("range", SyntaxShape::Range, "Range of values") .optional("range", SyntaxShape::Range, "Range of values")
.category(Category::Random) .category(Category::Random)
} }

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, ListStream, PipelineData, ShellError, Signature, SyntaxShape, Value, Category, Example, ListStream, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
}; };
use rand::prelude::{thread_rng, Rng}; use rand::prelude::{thread_rng, Rng};
@ -16,6 +16,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random dice") Signature::build("random dice")
.input_output_types(vec![(Type::Nothing, Type::ListStream)])
.allow_variants_without_examples(true)
.named( .named(
"dice", "dice",
SyntaxShape::Int, SyntaxShape::Int,

View File

@ -2,7 +2,7 @@ use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, Range, ShellError, Signature, SyntaxShape, Value, Category, Example, PipelineData, Range, ShellError, Signature, SyntaxShape, Type, Value,
}; };
use rand::prelude::{thread_rng, Rng}; use rand::prelude::{thread_rng, Rng};
use std::cmp::Ordering; use std::cmp::Ordering;
@ -17,6 +17,8 @@ impl Command for SubCommand {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random integer") Signature::build("random integer")
.input_output_types(vec![(Type::Nothing, Type::Int)])
.allow_variants_without_examples(true)
.optional("range", SyntaxShape::Range, "Range of values") .optional("range", SyntaxShape::Range, "Range of values")
.category(Category::Random) .category(Category::Random)
} }

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for RandomCommand {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random").category(Category::Random) Signature::build("random")
.category(Category::Random)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,6 +1,6 @@
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Value}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type, Value};
use uuid::Uuid; use uuid::Uuid;
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,10 @@ impl Command for SubCommand {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("random uuid").category(Category::Random) Signature::build("random uuid")
.category(Category::Random)
.input_output_types(vec![(Type::Nothing, Type::String)])
.allow_variants_without_examples(true)
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,9 @@ use super::{get_current_shell, get_shells};
use nu_engine::{current_dir, CallExt}; use nu_engine::{current_dir, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -15,6 +17,7 @@ impl Command for Enter {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("enter") Signature::build("enter")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required( .required(
"path", "path",
SyntaxShape::Filepath, SyntaxShape::Filepath,

View File

@ -2,7 +2,9 @@ use super::{get_current_shell, get_last_shell, get_shells};
use nu_engine::{current_dir, CallExt}; use nu_engine::{current_dir, CallExt};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
};
#[derive(Clone)] #[derive(Clone)]
pub struct Exit; pub struct Exit;
@ -14,6 +16,7 @@ impl Command for Exit {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("exit") Signature::build("exit")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.optional( .optional(
"exit_code", "exit_code",
SyntaxShape::Int, SyntaxShape::Int,

View File

@ -2,7 +2,9 @@ use super::{list_shells, switch_shell, SwitchTo};
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape}; use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -15,6 +17,10 @@ impl Command for GotoShell {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("g") Signature::build("g")
.input_output_types(vec![
(Type::Nothing, Type::Nothing),
(Type::Nothing, Type::Table(vec![])),
])
.optional( .optional(
"shell_number", "shell_number",
SyntaxShape::String, SyntaxShape::String,

View File

@ -1,7 +1,7 @@
use super::{switch_shell, SwitchTo}; use super::{switch_shell, SwitchTo};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -13,7 +13,9 @@ impl Command for NextShell {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("n").category(Category::Shells) Signature::build("n")
.category(Category::Shells)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use super::{switch_shell, SwitchTo}; use super::{switch_shell, SwitchTo};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -13,7 +13,9 @@ impl Command for PrevShell {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("p").category(Category::Shells) Signature::build("p")
.category(Category::Shells)
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -1,7 +1,7 @@
use super::list_shells; use super::list_shells;
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature}; use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
/// Source a file for environment variables. /// Source a file for environment variables.
#[derive(Clone)] #[derive(Clone)]
@ -13,7 +13,9 @@ impl Command for Shells {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("shells").category(Category::Shells) Signature::build("shells")
.category(Category::Shells)
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for SplitCommand {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("split").category(Category::Strings) Signature::build("split")
.category(Category::Strings)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -41,16 +43,3 @@ impl Command for SplitCommand {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
// #[cfg(test)]
// mod tests {
// use super::Command;
// use super::ShellError;
// #[test]
// fn examples_work_as_expected() -> Result<(), ShellError> {
// use crate::examples::test as test_examples;
// test_examples(Command {})
// }
// }

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value, Category, IntoPipelineData, PipelineData, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for Str {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("str").category(Category::Strings) Signature::build("str")
.category(Category::Strings)
.input_output_types(vec![(Type::Nothing, Type::String)])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -41,15 +43,3 @@ impl Command for Str {
.into_pipeline_data()) .into_pipeline_data())
} }
} }
#[cfg(test)]
mod test {
use crate::Str;
#[test]
fn test_examples() {
use crate::test_examples;
test_examples(Str {})
}
}

View File

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -13,7 +13,9 @@ impl Command for Complete {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("complete").category(Category::System) Signature::build("complete")
.category(Category::System)
.input_output_types(vec![(Type::Any, Type::Record(vec![]))])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -3,7 +3,7 @@ use nu_engine::{current_dir, env_to_strings, CallExt};
use nu_protocol::{ use nu_protocol::{
ast::{Call, Expr}, ast::{Call, Expr},
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
}; };
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
@ -17,6 +17,7 @@ impl Command for Exec {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("exec") Signature::build("exec")
.input_output_types(vec![(Type::Nothing, Type::Any)])
.required("command", SyntaxShape::String, "the command to execute") .required("command", SyntaxShape::String, "the command to execute")
.rest( .rest(
"rest", "rest",

View File

@ -3,7 +3,7 @@ use nu_parser::{parse, parse_module_block, unescape_unquote_string};
use nu_protocol::ast::Call; use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack, StateWorkingSet}; use nu_protocol::engine::{Command, EngineState, Stack, StateWorkingSet};
use nu_protocol::{ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -16,6 +16,9 @@ impl Command for NuCheck {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("nu-check") Signature::build("nu-check")
.input_output_types(vec![(Type::String, Type::Bool),
(Type::ListStream, Type::Bool),
(Type::List(Box::new(Type::Any)), Type::Bool)])
// type is string to avoid automatically canonicalizing the path // type is string to avoid automatically canonicalizing the path
.optional("path", SyntaxShape::String, "File path to parse") .optional("path", SyntaxShape::String, "File path to parse")
.switch("as-module", "Parse content as module", Some('m')) .switch("as-module", "Parse content as module", Some('m'))

View File

@ -3,7 +3,8 @@ use std::time::Duration;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Value, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Type,
Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -16,6 +17,7 @@ impl Command for Ps {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("ps") Signature::build("ps")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.switch( .switch(
"long", "long",
"list all available columns for each entry", "list all available columns for each entry",

View File

@ -3,7 +3,7 @@ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError, Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, ShellError,
Signature, Span, Spanned, SyntaxShape, Value, Signature, Span, Spanned, SyntaxShape, Type, Value,
}; };
use winreg::{enums::*, RegKey}; use winreg::{enums::*, RegKey};
@ -31,6 +31,7 @@ impl Command for RegistryQuery {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("registry query") Signature::build("registry query")
.input_output_types(vec![(Type::Nothing, Type::Any)])
.switch("hkcr", "query the hkey_classes_root hive", None) .switch("hkcr", "query the hkey_classes_root hive", None)
.switch("hkcu", "query the hkey_current_user hive", None) .switch("hkcu", "query the hkey_current_user hive", None)
.switch("hklm", "query the hkey_local_machine hive", None) .switch("hklm", "query the hkey_local_machine hive", None)

View File

@ -2,11 +2,13 @@ use fancy_regex::Regex;
use itertools::Itertools; use itertools::Itertools;
use nu_engine::env_to_strings; use nu_engine::env_to_strings;
use nu_engine::CallExt; use nu_engine::CallExt;
use nu_protocol::ast::{Expr, Expression}; use nu_protocol::{
use nu_protocol::did_you_mean; ast::{Call, Expr, Expression},
use nu_protocol::engine::{EngineState, Stack}; did_you_mean,
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value}; engine::{Command, EngineState, Stack},
use nu_protocol::{Category, Example, ListStream, PipelineData, RawStream, Span, Spanned}; Category, Example, ListStream, PipelineData, RawStream, ShellError, Signature, Span, Spanned,
SyntaxShape, Type, Value,
};
use nu_system::ForegroundProcess; use nu_system::ForegroundProcess;
use pathdiff::diff_paths; use pathdiff::diff_paths;
use std::collections::HashMap; use std::collections::HashMap;
@ -34,6 +36,7 @@ impl Command for External {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build(self.name()) Signature::build(self.name())
.input_output_types(vec![(Type::Any, Type::Any)])
.switch("redirect-stdout", "redirect stdout to the pipeline", None) .switch("redirect-stdout", "redirect stdout to the pipeline", None)
.switch("redirect-stderr", "redirect stderr to the pipeline", None) .switch("redirect-stderr", "redirect stderr to the pipeline", None)
.switch("trim-end-newline", "trimming end newlines", None) .switch("trim-end-newline", "trimming end newlines", None)

View File

@ -3,7 +3,7 @@ use chrono::Local;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use std::time::{Duration, UNIX_EPOCH}; use std::time::{Duration, UNIX_EPOCH};
use sysinfo::{ComponentExt, CpuExt, DiskExt, NetworkExt, System, SystemExt, UserExt}; use sysinfo::{ComponentExt, CpuExt, DiskExt, NetworkExt, System, SystemExt, UserExt};
@ -17,7 +17,10 @@ impl Command for Sys {
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("sys").filter().category(Category::System) Signature::build("sys")
.filter()
.category(Category::System)
.input_output_types(vec![(Type::Nothing, Type::Record(vec![]))])
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {

View File

@ -6,7 +6,7 @@ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
Spanned, SyntaxShape, Value, Spanned, SyntaxShape, Type, Value,
}; };
use std::ffi::OsStr; use std::ffi::OsStr;
@ -22,6 +22,8 @@ impl Command for Which {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("which") Signature::build("which")
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
.allow_variants_without_examples(true)
.required("application", SyntaxShape::String, "application") .required("application", SyntaxShape::String, "application")
.rest("rest", SyntaxShape::String, "additional applications") .rest("rest", SyntaxShape::String, "additional applications")
.switch("all", "list all executables", Some('a')) .switch("all", "list all executables", Some('a'))

View File

@ -9,7 +9,7 @@ use nu_explore::{
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use std::collections::HashMap; use std::collections::HashMap;
@ -31,6 +31,7 @@ impl Command for Explore {
// if we set h i short flags it panics???? // if we set h i short flags it panics????
Signature::build("explore") Signature::build("explore")
.input_output_types(vec![(Type::Any, Type::Any)])
.named( .named(
"head", "head",
SyntaxShape::Boolean, SyntaxShape::Boolean,

View File

@ -7,7 +7,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack, StateWorkingSet}, engine::{Command, EngineState, Stack, StateWorkingSet},
format_error, Category, Config, DataSource, Example, FooterMode, IntoPipelineData, ListStream, format_error, Category, Config, DataSource, Example, FooterMode, IntoPipelineData, ListStream,
PipelineData, PipelineMetadata, RawStream, ShellError, Signature, Span, SyntaxShape, PipelineData, PipelineMetadata, RawStream, ShellError, Signature, Span, SyntaxShape,
TableIndexMode, Value, TableIndexMode, Type, Value,
}; };
use nu_table::{string_width, Table as NuTable, TableConfig, TableTheme}; use nu_table::{string_width, Table as NuTable, TableConfig, TableTheme};
use nu_utils::get_ls_colors; use nu_utils::get_ls_colors;
@ -57,6 +57,8 @@ impl Command for Table {
fn signature(&self) -> nu_protocol::Signature { fn signature(&self) -> nu_protocol::Signature {
Signature::build("table") Signature::build("table")
.input_output_types(vec![(Type::Any, Type::Any)])
// TODO: make this more precise: what turns into string and what into raw stream
.named( .named(
"start-number", "start-number",
SyntaxShape::Int, SyntaxShape::Int,

View File

@ -1,5 +1,5 @@
use nu_command::create_default_context; use nu_command::create_default_context;
use nu_protocol::engine::StateWorkingSet; use nu_protocol::{engine::StateWorkingSet, Category};
use quickcheck_macros::quickcheck; use quickcheck_macros::quickcheck;
mod commands; mod commands;
@ -49,6 +49,37 @@ fn signature_name_matches_command_name() {
); );
} }
#[test]
fn commands_declare_input_output_types() {
let ctx = crate::create_default_context();
let decls = ctx.get_decl_ids_sorted(true);
let mut failures = Vec::new();
for decl_id in decls {
let cmd = ctx.get_decl(decl_id);
let sig_name = cmd.signature().name;
let category = cmd.signature().category;
if matches!(category, Category::Deprecated | Category::Custom(_)) {
// Deprecated commands don't have to conform
// TODO: also upgrade the `--features dataframe` commands
continue;
}
if cmd.signature().input_output_types.is_empty() {
failures.push(format!(
"{sig_name} ({category:?}): No pipeline input/output type signatures found"
));
}
}
assert!(
failures.is_empty(),
"Command missing type annotations:\n{}",
failures.join("\n")
);
}
#[test] #[test]
fn no_search_term_duplicates() { fn no_search_term_duplicates() {
let ctx = crate::create_default_context(); let ctx = crate::create_default_context();