docs: Add comprehensive Rustdoc for shell meta plugin

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 15:31:53 -03:00
parent 0e036e3789
commit 2a4a7d46c4

View File

@@ -3,6 +3,11 @@ use std::env;
use crate::meta_plugin::{MetaPlugin, MetaPluginType};
#[derive(Debug, Clone, Default)]
/// Meta plugin for capturing shell environment information.
///
/// This plugin retrieves the current shell from the SHELL environment variable
/// and provides it as metadata. It runs once during initialization and does not
/// process input data.
pub struct ShellMetaPlugin {
is_finalized: bool,
outputs: std::collections::HashMap<String, serde_yaml::Value>,
@@ -10,6 +15,25 @@ pub struct ShellMetaPlugin {
}
impl ShellMetaPlugin {
/// Creates a new ShellMetaPlugin instance.
///
/// Initializes with default outputs and options, overridden by provided values.
/// Defaults to "shell" as the output key.
///
/// # Arguments
///
/// * `_options` - Optional configuration options (unused currently).
/// * `outputs` - Optional output mappings to override defaults.
///
/// # Returns
///
/// * `ShellMetaPlugin` - A new instance with processed options and outputs.
///
/// # Examples
///
/// ```
/// let plugin = ShellMetaPlugin::new(None, None);
/// ```
pub fn new(
_options: Option<std::collections::HashMap<String, serde_yaml::Value>>,
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
@@ -44,14 +68,31 @@ impl ShellMetaPlugin {
}
impl MetaPlugin for ShellMetaPlugin {
/// Checks if the plugin has been finalized.
///
/// # Returns
///
/// * `bool` - True if finalized, false otherwise.
fn is_finalized(&self) -> bool {
self.is_finalized
}
/// Sets the finalized state of the plugin.
///
/// # Arguments
///
/// * `finalized` - The new finalized state.
fn set_finalized(&mut self, finalized: bool) {
self.is_finalized = finalized;
}
/// Finalizes the plugin without processing data.
///
/// For this plugin, finalization is handled in `initialize`, so this returns empty metadata.
///
/// # Returns
///
/// * `MetaPluginResponse` - Response with no metadata and finalized state.
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process again
if self.is_finalized {
@@ -70,6 +111,17 @@ impl MetaPlugin for ShellMetaPlugin {
}
}
/// Updates the plugin with data (not used for shell).
///
/// Shell plugin doesn't process data streams; returns empty response unless not finalized.
///
/// # Arguments
///
/// * `_data` - Byte slice of input data (ignored).
///
/// # Returns
///
/// * `MetaPluginResponse` - Empty metadata response.
fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process more data
if self.is_finalized {
@@ -85,10 +137,31 @@ impl MetaPlugin for ShellMetaPlugin {
}
}
/// Returns the type of this meta plugin.
///
/// # Returns
///
/// * `MetaPluginType::Shell` - The shell plugin type.
fn meta_type(&self) -> MetaPluginType {
MetaPluginType::Shell
}
/// Initializes the plugin and extracts shell metadata.
///
/// Retrieves the SHELL environment variable and adds it to metadata.
/// Marks the plugin as finalized after one run.
///
/// # Returns
///
/// * `MetaPluginResponse` - Response with shell metadata and finalized state.
///
/// # Examples
///
/// ```
/// let mut plugin = ShellMetaPlugin::new(None, None);
/// let response = plugin.initialize();
/// assert!(response.is_finalized);
/// ```
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
// If already finalized, don't process again
if self.is_finalized {
@@ -122,24 +195,48 @@ impl MetaPlugin for ShellMetaPlugin {
}
}
/// Returns a reference to the plugin's outputs.
///
/// # Returns
///
/// * `&HashMap<String, serde_yaml::Value>` - The outputs map.
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
/// Returns a mutable reference to the plugin's outputs.
///
/// # Returns
///
/// * `&mut HashMap<String, serde_yaml::Value>` - Mutable outputs map.
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
/// Returns a reference to the plugin's options.
///
/// # Returns
///
/// * `&HashMap<String, serde_yaml::Value>` - The options map.
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.options
}
/// Returns a mutable reference to the plugin's options.
///
/// # Returns
///
/// * `&mut HashMap<String, serde_yaml::Value>` - Mutable options map.
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.options
}
}
/// Registers the shell meta plugin with the global registry.
///
/// This constructor function is called at module load time using ctor crate.
/// It creates the plugin with provided options and outputs.
use crate::meta_plugin::register_meta_plugin;
// Register the plugin at module initialization time