Skip to main content

Crate metarepo_plugin_sdk

Crate metarepo_plugin_sdk 

Source
Expand description

§metarepo-plugin-sdk

Author a metarepo external plugin by implementing one trait and calling serve. The SDK owns the v1 stdio wire protocol — request framing, parsing, dispatch, error handling, and the protocol-version handshake — so plugin code never touches stdin/stdout or JSON directly.

use metarepo_plugin_sdk::{serve, 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", "Print a greeting")]
    }

    fn handle(
        &self,
        _command: &str,
        _args: &[String],
        _config: &RuntimeConfigDto,
    ) -> anyhow::Result<Option<String>> {
        Ok(Some("hello from a plugin".to_string()))
    }
}

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

Structs§

ArgInfo
Declarative description of a single command argument.
CommandInfo
Declarative description of a command (and its subcommands/args) that a plugin exposes. The host rebuilds clap commands from this over the wire.
RuntimeConfigDto
Serializable snapshot of RuntimeConfig passed to a plugin over the wire.

Enums§

PluginRequest
A request sent from the host to a plugin subprocess.
PluginResponse
A response sent from a plugin subprocess back to the host.

Constants§

PLUGIN_PROTOCOL_VERSION
Wire-format protocol version this build speaks. Plugins must report a matching major version in their PluginResponse::Info or the host refuses to load them.

Traits§

Plugin
A metarepo plugin. Implement this trait and pass an instance to serve.

Functions§

serve
Run the plugin against the process stdin/stdout.
serve_io
Run the request loop against arbitrary reader/writer streams.