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
78 changed files with 324 additions and 186 deletions

View File

@ -2,7 +2,7 @@ use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, Signature, Value,
Category, IntoPipelineData, PipelineData, Signature, Type, Value,
};
#[derive(Clone)]
@ -14,7 +14,9 @@ impl Command for ConfigMeta {
}
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 {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_strings;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Type,
};
use crate::ExternalCommand;
@ -18,7 +18,10 @@ impl Command for ConfigEnv {
}
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 {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_strings;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned,
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, Type,
};
use crate::ExternalCommand;
@ -18,7 +18,10 @@ impl Command for ConfigNu {
}
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 {

View File

@ -2,7 +2,7 @@ use nu_engine::env_to_string;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Value,
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
};
#[derive(Clone)]
@ -18,7 +18,9 @@ impl Command for Env {
}
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(

View File

@ -2,7 +2,7 @@ use nu_engine::{eval_expression_with_input, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value,
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -19,6 +19,8 @@ impl Command for LetEnv {
fn signature(&self) -> nu_protocol::Signature {
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(
"initial_value",

View File

@ -1,7 +1,9 @@
use nu_engine::{current_dir, CallExt};
use nu_protocol::ast::Call;
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)]
pub struct LoadEnv;
@ -17,6 +19,8 @@ impl Command for LoadEnv {
fn signature(&self) -> nu_protocol::Signature {
Signature::build("load-env")
.input_output_types(vec![(Type::Record(vec![]), Type::Nothing)])
.allow_variants_without_examples(true)
.optional(
"update",
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::engine::{Command, EngineState, Stack};
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.
@ -18,6 +18,7 @@ impl Command for SourceEnv {
fn signature(&self) -> Signature {
Signature::build("source-env")
.input_output_types(vec![(Type::Any, Type::Any)])
.required(
"filename",
SyntaxShape::String, // type is string to avoid automatically canonicalizing the path