metarepo-plugin-sdk 0.21.0

SDK for authoring external plugins for the metarepo CLI: implement a trait, call serve(), and the v1 stdio protocol is handled for you
Documentation

metarepo-plugin-sdk

SDK for authoring external plugins for the metarepo CLI. Implement one trait, call serve(), and the v1 stdio wire protocol — request framing, JSON, dispatch, error handling, and the protocol-version handshake — is handled for you.

use metarepo_plugin_sdk::{serve, ArgInfo, CommandInfo, Plugin, RuntimeConfigDto};

struct Hello;

impl Plugin for Hello {
    fn name(&self) -> &str { "hello" }
    fn version(&self) -> &str { env!("CARGO_PKG_VERSION") }

    fn commands(&self) -> Vec<CommandInfo> {
        vec![CommandInfo::new("hello", "Greeting commands").subcommand(
            CommandInfo::new("greet", "Print a greeting")
                .arg(ArgInfo::new("name", "Name to greet", true)),
        )]
    }

    fn handle(
        &self,
        _command: &str,
        args: &[String],
        _config: &RuntimeConfigDto,
    ) -> anyhow::Result<Option<String>> {
        let name = args.get(1).map(String::as_str).unwrap_or("world");
        Ok(Some(format!("Hello, {name}!")))
    }
}

fn main() -> anyhow::Result<()> {
    serve(Hello)
}

The protocol types (PluginRequest, PluginResponse, CommandInfo, ArgInfo, RuntimeConfigDto) are re-exported from metarepo_core::protocol, so a plugin depends only on this crate.

Testing your plugin

serve_io(plugin, reader, writer) runs the request loop against arbitrary streams, so you can drive it with in-memory buffers in unit tests. You can also unit-test the Plugin trait methods directly, independent of the transport.

License

MIT