mirror of
https://github.com/nushell/nushell.git
synced 2025-03-26 07:19:55 +01: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
41 lines
1.4 KiB
Rust
41 lines
1.4 KiB
Rust
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
|
use nu_protocol::{Category, PluginSignature, SyntaxShape, Value};
|
|
|
|
use crate::Example;
|
|
|
|
pub struct Three;
|
|
|
|
impl SimplePluginCommand for Three {
|
|
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 three")
|
|
.usage("PluginSignature test 3 for plugin. Returns labeled error")
|
|
.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")
|
|
.category(Category::Experimental)
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
plugin: &Example,
|
|
_engine: &EngineInterface,
|
|
call: &EvaluatedCall,
|
|
input: &Value,
|
|
) -> Result<Value, LabeledError> {
|
|
plugin.print_values(3, call, input)?;
|
|
|
|
Err(LabeledError {
|
|
label: "ERROR from plugin".into(),
|
|
msg: "error message pointing to call head span".into(),
|
|
span: Some(call.head),
|
|
})
|
|
}
|
|
}
|