Expand description
Plugin system for dynamic-cli
This module defines the Plugin trait, the standard extension mechanism
for dynamic-cli applications. A plugin groups related command handlers
under a single unit of deployment with explicit metadata.
§Design
The plugin system follows the principle established by DD-001 and DD-002:
- The YAML config is the sole source of truth for command definitions.
- Plugins supply handlers only — identified by their
implementationname, exactly as [CliBuilder::register_handler] does. - The framework controls registration — the plugin declares what it
provides via
Plugin::handlers; the framework validates and registers. The plugin never receives a&mut CommandRegistry.
§Standard plugin
SystemPlugin is provided out of the box. It supplies handlers for the
common system commands (help, version, exit / quit) that every
application typically needs. Users declare the corresponding commands in
their YAML config and register the plugin with a single call.
§Example
use dynamic_cli::plugin::{Plugin, SystemPlugin};
use dynamic_cli::executor::CommandHandler;
use std::collections::HashMap;
// A minimal plugin supplying one handler
struct GreetPlugin;
impl Plugin for GreetPlugin {
fn name(&self) -> &str { "greet" }
fn version(&self) -> &str { "0.1.0" }
fn description(&self) -> &str { "Greeting commands" }
fn handlers(&self) -> Vec<(String, Box<dyn CommandHandler>)> {
struct HelloHandler;
impl CommandHandler for HelloHandler {
fn execute(
&self,
_ctx: &mut dyn dynamic_cli::context::ExecutionContext,
args: &HashMap<String, String>,
) -> dynamic_cli::Result<()> {
let default = "World".to_string();
println!("Hello, {}!", args.get("name").unwrap_or(&default));
Ok(())
}
}
vec![("greet_hello".to_string(), Box::new(HelloHandler))]
}
}
// Verify the trait contract
let plugin = GreetPlugin;
assert_eq!(plugin.name(), "greet");
let handlers = plugin.handlers();
assert_eq!(handlers.len(), 1);
assert_eq!(handlers[0].0, "greet_hello");Re-exports§
pub use system::SystemPlugin;
Modules§
- system
- Built-in system plugin for
dynamic-cli - wasm
- WASM plugin loader for
dynamic-cli(Option C — DD-021)
Traits§
- Plugin
- Extension point for grouping related command handlers.