refactor: Display filter plugin details in status command

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-03 09:17:42 -03:00
parent e5f71c7c5d
commit 332a609d7f

View File

@@ -122,7 +122,7 @@ fn build_compression_table(compression_info: &Vec<CompressionInfo>) -> Table {
compression_table compression_table
} }
fn build_filter_plugin_table(filter_plugins: &Vec<String>) -> Table { fn build_filter_plugin_table(filter_plugins: &Vec<crate::common::status::FilterPluginInfo>) -> Table {
let mut filter_plugin_table = Table::new(); let mut filter_plugin_table = Table::new();
if std::io::stdout().is_terminal() { if std::io::stdout().is_terminal() {
filter_plugin_table.set_format(*FORMAT_BOX_CHARS); filter_plugin_table.set_format(*FORMAT_BOX_CHARS);
@@ -136,26 +136,26 @@ fn build_filter_plugin_table(filter_plugins: &Vec<String>) -> Table {
b->"Description")); b->"Description"));
// Sort plugins by name // Sort plugins by name
let mut sorted_plugin_names = filter_plugins.clone(); let mut sorted_plugins = filter_plugins.clone();
sorted_plugin_names.sort(); sorted_plugins.sort_by(|a, b| a.name.cmp(&b.name));
for plugin_name in sorted_plugin_names {
// Get the plugin creator
let filter_plugins_map = get_available_filter_plugins();
if let Some(plugin_creator) = filter_plugins_map.get(&plugin_name) {
// Create a temporary instance to get options
let plugin = plugin_creator();
// Get options
let options = plugin.options();
for plugin_info in sorted_plugins {
// Format options as YAML string // Format options as YAML string
let options_str = if options.is_empty() { let options_str = if plugin_info.options.is_empty() {
"{}".to_string() "{}".to_string()
} else { } else {
let options_map: std::collections::BTreeMap<_, _> = options // Convert options to a map for better display
let options_map: std::collections::BTreeMap<_, _> = plugin_info.options
.iter() .iter()
.map(|opt| (opt.name.clone(), serde_yaml::to_value(opt).unwrap())) .map(|opt| {
let mut opt_map = std::collections::BTreeMap::new();
opt_map.insert("name", &opt.name);
if let Some(default) = &opt.default {
opt_map.insert("default", default);
}
opt_map.insert("required", &opt.required);
(opt.name.clone(), serde_yaml::Value::String(format!("{:?}", opt_map)))
})
.collect(); .collect();
serde_yaml::to_string(&options_map) serde_yaml::to_string(&options_map)
.unwrap_or_else(|_| "Unable to serialize options".to_string()) .unwrap_or_else(|_| "Unable to serialize options".to_string())
@@ -163,16 +163,12 @@ fn build_filter_plugin_table(filter_plugins: &Vec<String>) -> Table {
.to_string() .to_string()
}; };
// Use a default description
let description = "Filter plugin".to_string();
filter_plugin_table.add_row(Row::new(vec![ filter_plugin_table.add_row(Row::new(vec![
Cell::new(&plugin_name), Cell::new(&plugin_info.name),
Cell::new(&options_str), Cell::new(&options_str),
Cell::new(&description), Cell::new(&plugin_info.description),
])); ]));
} }
}
// If no filter plugins are available, add a row indicating that // If no filter plugins are available, add a row indicating that
if filter_plugins.is_empty() { if filter_plugins.is_empty() {