Bidirectional communication and streams for plugins (#11911)

This commit is contained in:
Devyn Cairns
2024-02-25 14:32:50 -08:00
committed by GitHub
parent 461f69ac5d
commit 88f1f386bb
47 changed files with 8025 additions and 1496 deletions

View File

@ -4,7 +4,7 @@ mod second_custom_value;
use cool_custom_value::CoolCustomValue;
use nu_plugin::{serve_plugin, MsgPackSerializer, Plugin};
use nu_plugin::{EvaluatedCall, LabeledError};
use nu_protocol::{Category, PluginSignature, ShellError, Value};
use nu_protocol::{Category, PluginSignature, ShellError, SyntaxShape, Value};
use second_custom_value::SecondCustomValue;
struct CustomValuePlugin;
@ -21,6 +21,14 @@ impl Plugin for CustomValuePlugin {
PluginSignature::build("custom-value update")
.usage("PluginSignature for a plugin that updates a custom value")
.category(Category::Experimental),
PluginSignature::build("custom-value update-arg")
.usage("PluginSignature for a plugin that updates a custom value as an argument")
.required(
"custom_value",
SyntaxShape::Any,
"the custom value to update",
)
.category(Category::Experimental),
]
}
@ -35,6 +43,7 @@ impl Plugin for CustomValuePlugin {
"custom-value generate" => self.generate(call, input),
"custom-value generate2" => self.generate2(call, input),
"custom-value update" => self.update(call, input),
"custom-value update-arg" => self.update(call, &call.req(0)?),
_ => Err(LabeledError {
label: "Plugin call with wrong name signature".into(),
msg: "the signature used to call the plugin does not match any name in the plugin signature vector".into(),