finish up with examples (#4637)

This commit is contained in:
JT 2022-02-25 05:19:25 -05:00 committed by GitHub
parent 2b1e4dd242
commit e8a6458f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 3 deletions

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, Example, IntoPipelineData, PipelineData, Signature, Span, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -39,4 +39,15 @@ impl Command for ExportCommand {
} }
.into_pipeline_data()) .into_pipeline_data())
} }
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Export a definition from a module",
example: r#"module utils { export def my-command [] { "hello" } }; use utils my-command; my-command"#,
result: Some(Value::String {
val: "hello".to_string(),
span: Span::test_data(),
}),
}]
}
} }

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, PipelineData, Signature, SyntaxShape}; use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape};
#[derive(Clone)] #[derive(Clone)]
pub struct Extern; pub struct Extern;
@ -30,4 +30,12 @@ impl Command for Extern {
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> { ) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Ok(PipelineData::new(call.head)) Ok(PipelineData::new(call.head))
} }
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Write a signature for an external command",
example: r#"extern echo [text: string]"#,
result: None,
}]
}
} }

View File

@ -8,7 +8,7 @@ use std::sync::mpsc;
use nu_engine::env_to_strings; use nu_engine::env_to_strings;
use nu_protocol::engine::{EngineState, Stack}; use nu_protocol::engine::{EngineState, Stack};
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value}; use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
use nu_protocol::{Category, PipelineData, RawStream, Span, Spanned}; use nu_protocol::{Category, Example, PipelineData, RawStream, Span, Spanned};
use itertools::Itertools; use itertools::Itertools;
@ -93,6 +93,14 @@ impl Command for External {
}; };
command.run_with_input(engine_state, stack, input) command.run_with_input(engine_state, stack, input)
} }
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Run an external command",
example: r#"run-external "echo" "-n" "hello""#,
result: None,
}]
}
} }
pub struct ExternalCommand { pub struct ExternalCommand {