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:
Dan Davison
2022-11-09 16:55:05 -05:00
committed by GitHub
parent f878276de7
commit df94052180
238 changed files with 2315 additions and 756 deletions

View File

@ -2,7 +2,7 @@ use nu_engine::{eval_block, redirect_env, CallExt};
use nu_protocol::{
ast::Call,
engine::{CaptureBlock, Command, EngineState, Stack},
Category, Example, PipelineData, Signature, Span, SyntaxShape, Value,
Category, Example, PipelineData, Signature, Span, SyntaxShape, Type, Value,
};
#[derive(Clone)]
@ -15,6 +15,7 @@ impl Command for ExportEnv {
fn signature(&self) -> Signature {
Signature::build("export-env")
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
.required(
"block",
SyntaxShape::Block(Some(vec![])),
@ -53,11 +54,20 @@ impl Command for ExportEnv {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Set an environment",
example: r#"export-env { let-env SPAM = 'eggs' }; $env.SPAM"#,
result: Some(Value::string("eggs", Span::test_data())),
}]
vec![
Example {
description: "Set an environment variable",
example: r#"export-env { let-env SPAM = 'eggs' }"#,
result: Some(Value::Nothing {
span: Span::test_data(),
}),
},
Example {
description: "Set an environment variable and examine its value",
example: r#"export-env { let-env SPAM = 'eggs' }; $env.SPAM"#,
result: Some(Value::string("eggs", Span::test_data())),
},
]
}
}