diff --git a/src/modes/status.rs b/src/modes/status.rs index 05759ce..9581a60 100644 --- a/src/modes/status.rs +++ b/src/modes/status.rs @@ -297,10 +297,6 @@ pub fn mode_status( build_path_table(&status_info.paths).printstd(); println!(); - println!("COMPRESSION:"); - build_compression_table(&status_info.compression).printstd(); - println!(); - // Always try to print META PLUGINS CONFIGURED section if let Some(meta_plugins_table) = build_meta_plugins_configured_table(settings) { println!("META PLUGINS CONFIGURED:"); diff --git a/src/modes/status_plugins.rs b/src/modes/status_plugins.rs index 07fb9f9..c262ab9 100644 --- a/src/modes/status_plugins.rs +++ b/src/modes/status_plugins.rs @@ -13,150 +13,9 @@ use prettytable::{Attr, Cell, Row, Table}; use prettytable::format::consts::{FORMAT_BOX_CHARS, FORMAT_NO_BORDER_LINE_SEPARATOR}; use crate::meta_plugin::{MetaPluginType, get_meta_plugin}; -use crate::common::status::{MetaPluginInfo}; +use crate::common::status::{MetaPluginInfo, CompressionInfo}; +use prettytable::color; -fn build_meta_plugins_configured_table(settings: &config::Settings) -> Option { - let meta_plugins = settings.meta_plugins.as_ref()?; - if meta_plugins.is_empty() { - return None; - } - - // Sort meta plugins by name - let mut sorted_meta_plugins = meta_plugins.clone(); - sorted_meta_plugins.sort_by(|a, b| a.name.cmp(&b.name)); - - let mut table = Table::new(); - if std::io::stdout().is_terminal() { - table.set_format(*FORMAT_BOX_CHARS); - } else { - table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR); - } - - table.set_titles(Row::new(vec![ - Cell::new("Plugin Name").with_style(Attr::Bold), - Cell::new("Options").with_style(Attr::Bold), - Cell::new("Outputs").with_style(Attr::Bold), - ])); - - for plugin_config in sorted_meta_plugins { - // Create the plugin to get its default options - let meta_plugin_type = match MetaPluginType::from_str(&plugin_config.name) { - Ok(plugin_type) => plugin_type, - Err(_) => continue, - }; - - // First, create a default plugin to get its default options - let default_plugin = get_meta_plugin( - meta_plugin_type.clone(), - None, - None, - ); - - // Start with the default options - let mut effective_options = default_plugin.options().clone(); - - // Merge with the configured options - for (key, value) in &plugin_config.options { - effective_options.insert(key.clone(), value.clone()); - } - - // Convert outputs from HashMap to HashMap - let outputs_converted: std::collections::HashMap = plugin_config.outputs - .iter() - .map(|(k, v)| (k.clone(), serde_yaml::Value::String(v.clone()))) - .collect(); - - // Create the actual plugin with merged options - the constructor will handle setting up outputs - let actual_plugin = get_meta_plugin( - meta_plugin_type.clone(), - Some(effective_options.clone()), - Some(outputs_converted), - ); - - // Get the default plugin to see its default options - let default_plugin = get_meta_plugin( - meta_plugin_type.clone(), - None, - None, - ); - - // Start with the default options - let mut all_options = default_plugin.options().clone(); - // Merge with the configured options - for (key, value) in &effective_options { - all_options.insert(key.clone(), value.clone()); - } - - // Sort options by key and convert to a YAML string - let mut sorted_options: Vec<_> = all_options.iter().collect(); - sorted_options.sort_by(|a, b| a.0.cmp(b.0)); - let sorted_options_map: std::collections::BTreeMap<_, _> = sorted_options.into_iter().collect(); - - let options_str = if sorted_options_map.is_empty() { - "{}".to_string() - } else { - serde_yaml::to_string(&sorted_options_map) - .unwrap_or_else(|_| "Unable to serialize options".to_string()) - .trim() - .to_string() - }; - - // Show only non-null outputs from the plugin - // Collect and sort outputs by their string representation - let mut enabled_output_pairs = Vec::new(); - for (key, value) in actual_plugin.outputs() { - // Skip null values (disabled outputs) - if value.is_null() { - continue; - } - - // Convert serde_yaml::Value to a string representation - let value_str = match value { - serde_yaml::Value::String(s) => s.clone(), - serde_yaml::Value::Number(n) => n.to_string(), - serde_yaml::Value::Bool(b) => b.to_string(), - serde_yaml::Value::Null => "null".to_string(), - serde_yaml::Value::Sequence(_) => { - serde_yaml::to_string(value).unwrap_or_else(|_| "[]".to_string()) - } - serde_yaml::Value::Mapping(_) => { - serde_yaml::to_string(value).unwrap_or_else(|_| "{}".to_string()) - } - serde_yaml::Value::Tagged(_) => { - serde_yaml::to_string(value).unwrap_or_else(|_| "tagged".to_string()) - } - }; - // Trim any extra whitespace from the serialized values - let value_str = value_str.trim().to_string(); - if key == &value_str { - enabled_output_pairs.push((key.clone(), key.clone())); - } else { - enabled_output_pairs.push((key.clone(), format!("{}->{}", key, value_str))); - } - } - - // Sort outputs by their display value (second element of the tuple) - enabled_output_pairs.sort_by(|a, b| a.1.cmp(&b.1)); - - // Join each output on a new line - let outputs_str = if enabled_output_pairs.is_empty() { - "{}".to_string() - } else { - enabled_output_pairs.into_iter() - .map(|(_, display)| display) - .collect::>() - .join("\n") - }; - - table.add_row(Row::new(vec![ - Cell::new(&plugin_config.name), - Cell::new(&options_str), - Cell::new(&outputs_str), - ])); - } - - Some(table) -} fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap) -> Table { let mut meta_plugin_table = Table::new(); @@ -223,6 +82,45 @@ fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap) -> Table { + let mut compression_table = Table::new(); + if std::io::stdout().is_terminal() { + compression_table.set_format(*FORMAT_BOX_CHARS); + } else { + compression_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR); + } + + compression_table.set_titles(row!( + b->"Type", + b->"Found", + b->"Enabled", + b->"Binary", + b->"Compress", + b->"Decompress")); + + for info in compression_info { + compression_table.add_row(Row::new(vec![ + Cell::new(&info.compression_type), + match info.found { + true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)), + false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)), + }, + match info.default { + true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)), + false => Cell::new("No"), + }, + match info.binary.as_str() { + "" => Cell::new(&info.binary).with_style(Attr::ForegroundColor(color::BRIGHT_BLACK)), + _ => Cell::new(&info.binary), + }, + Cell::new(&info.compress), + Cell::new(&info.decompress), + ])); + } + + compression_table +} + pub fn mode_status_plugins( cmd: &mut Command, settings: &config::Settings, @@ -239,9 +137,18 @@ pub fn mode_status_plugins( match output_format { OutputFormat::Table => { - println!("META PLUGINS AVAILABLE:"); + println!("META PLUGINS:"); build_meta_plugin_table(&status_info.meta_plugins).printstd(); println!(); + + println!("COMPRESSION PLUGINS:"); + build_compression_table(&status_info.compression).printstd(); + println!(); + + // TODO: Add FILTER PLUGINS section here + println!("FILTER PLUGINS:"); + println!("No filter plugins available"); + println!(); Ok(()) }, OutputFormat::Json => {