70 breaking releases

0.93.0 Apr 30, 2024
0.91.0 Mar 5, 2024
0.88.1 Dec 14, 2023
0.87.1 Nov 20, 2023
0.12.0 Mar 31, 2020

#452 in Command-line interface

Download history 784/week @ 2024-01-22 659/week @ 2024-01-29 1458/week @ 2024-02-05 1230/week @ 2024-02-12 1016/week @ 2024-02-19 1202/week @ 2024-02-26 1644/week @ 2024-03-04 1335/week @ 2024-03-11 891/week @ 2024-03-18 689/week @ 2024-03-25 2534/week @ 2024-04-01 1628/week @ 2024-04-08 1059/week @ 2024-04-15 919/week @ 2024-04-22 888/week @ 2024-04-29 481/week @ 2024-05-06

3,461 downloads per month
Used in 61 crates (60 directly)

MIT and maybe CC-PDDC

1MB
27K SLoC

nu-plugin

This crate provides the API for Nushell plugins. See the book for more information on how to get started.


lib.rs:

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 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 usage(&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.

Dependencies

~21–55MB
~1M SLoC