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:
22
crates/nu-command/src/env/export_env.rs
vendored
22
crates/nu-command/src/env/export_env.rs
vendored
@ -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())),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user