Expand description
§Nu Plugin: Plugin library for Nushell
This crate contains the interface necessary to build Nushell plugins in Rust. Additionally, it contains public, but undocumented, items used by Nushell itself to interface with Nushell plugins. This documentation focuses on the interface needed to write an independent plugin.
Nushell plugins are stand-alone applications that communicate with Nushell over stdin and stdout using a standardizes serialization framework to exchange the typed data that Nushell commands utilize natively.
A typical plugin application will define a struct that implements the Plugin
trait and then, in its main method, pass that Plugin
to the serve_plugin()
function, which will handle all of the input and output serialization when
invoked by Nushell.
use nu_plugin::{EvaluatedCall, MsgPackSerializer, serve_plugin};
use nu_plugin::{EngineInterface, Plugin, PluginCommand, SimplePluginCommand};
use nu_protocol::{LabeledError, Signature, Value};
struct MyPlugin;
struct MyCommand;
impl Plugin for MyPlugin {
fn version(&self) -> String {
env!("CARGO_PKG_VERSION").into()
}
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
vec![Box::new(MyCommand)]
}
}
impl SimplePluginCommand for MyCommand {
type Plugin = MyPlugin;
fn name(&self) -> &str {
"my-command"
}
fn description(&self) -> &str {
todo!();
}
fn signature(&self) -> Signature {
todo!();
}
fn run(
&self,
plugin: &MyPlugin,
engine: &EngineInterface,
call: &EvaluatedCall,
input: &Value
) -> Result<Value, LabeledError> {
todo!();
}
}
fn main() {
serve_plugin(&MyPlugin{}, MsgPackSerializer)
}
Nushell’s source tree contains a Plugin Example that demonstrates the full range of plugin capabilities.
Structs§
- Engine
Interface - A reference through which the nushell engine can be interacted with during execution.
- Evaluated
Call - A representation of the plugin’s invocation command including command line args
- Json
Serializer - A
PluginEncoder
that enables the plugin to communicate with Nushell with JSON serialized data. - MsgPack
Serializer - A
PluginEncoder
that enables the plugin to communicate with Nushell with MsgPack serialized data.
Traits§
- Plugin
- The API for a Nushell plugin
- Plugin
Command - The API for a Nushell plugin command
- Plugin
Encoder - Encoding scheme that defines a plugin’s communication protocol with Nu
- Simple
Plugin Command - The API for a simple Nushell plugin command
Functions§
- serve_
plugin - Function used to implement the communication protocol between nushell and an external plugin.