mirror of
https://github.com/nushell/nushell.git
synced 2025-05-05 23:42:56 +00:00
# Description As suggested by @WindSoilder, since plugins can now contain both simple commands that produce `Value` and commands that produce `PipelineData` without having to choose one or the other for the whole plugin, this change merges `stream_example` into `example`. # User-Facing Changes All of the example plugins are renamed. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting - [ ] Check nushell/nushell.github.io for any docs that match the command names changed
44 lines
1.6 KiB
Rust
44 lines
1.6 KiB
Rust
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
|
use nu_protocol::{Category, PluginExample, PluginSignature, SyntaxShape, Value};
|
|
|
|
use crate::Example;
|
|
|
|
pub struct One;
|
|
|
|
impl SimplePluginCommand for One {
|
|
type Plugin = Example;
|
|
|
|
fn signature(&self) -> PluginSignature {
|
|
// The signature defines the usage of the command inside Nu, and also automatically
|
|
// generates its help page.
|
|
PluginSignature::build("example one")
|
|
.usage("PluginSignature test 1 for plugin. Returns Value::Nothing")
|
|
.extra_usage("Extra usage for example one")
|
|
.search_terms(vec!["example".into()])
|
|
.required("a", SyntaxShape::Int, "required integer value")
|
|
.required("b", SyntaxShape::String, "required string value")
|
|
.switch("flag", "a flag for the signature", Some('f'))
|
|
.optional("opt", SyntaxShape::Int, "Optional number")
|
|
.named("named", SyntaxShape::String, "named string", Some('n'))
|
|
.rest("rest", SyntaxShape::String, "rest value string")
|
|
.plugin_examples(vec![PluginExample {
|
|
example: "example one 3 bb".into(),
|
|
description: "running example with an int value and string value".into(),
|
|
result: None,
|
|
}])
|
|
.category(Category::Experimental)
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
plugin: &Example,
|
|
_engine: &EngineInterface,
|
|
call: &EvaluatedCall,
|
|
input: &Value,
|
|
) -> Result<Value, LabeledError> {
|
|
plugin.print_values(1, call, input)?;
|
|
|
|
Ok(Value::nothing(call.head))
|
|
}
|
|
}
|