From 2a4a7d46c42c738e230280a5fc2042ab2ea70289 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 10 Sep 2025 15:31:53 -0300 Subject: [PATCH] docs: Add comprehensive Rustdoc for shell meta plugin Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) --- src/meta_plugin/shell.rs | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/meta_plugin/shell.rs b/src/meta_plugin/shell.rs index fb3b0c4..ea1cf42 100644 --- a/src/meta_plugin/shell.rs +++ b/src/meta_plugin/shell.rs @@ -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, @@ -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>, outputs: Option>, @@ -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` - The outputs map. fn outputs(&self) -> &std::collections::HashMap { &self.outputs } + /// Returns a mutable reference to the plugin's outputs. + /// + /// # Returns + /// + /// * `&mut HashMap` - Mutable outputs map. fn outputs_mut(&mut self) -> &mut std::collections::HashMap { &mut self.outputs } + /// Returns a reference to the plugin's options. + /// + /// # Returns + /// + /// * `&HashMap` - The options map. fn options(&self) -> &std::collections::HashMap { &self.options } + /// Returns a mutable reference to the plugin's options. + /// + /// # Returns + /// + /// * `&mut HashMap` - Mutable options map. fn options_mut(&mut self) -> &mut std::collections::HashMap { &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