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
}
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();
if std::io::stdout().is_terminal() {
filter_plugin_table.set_format(*FORMAT_BOX_CHARS);
@@ -136,42 +136,38 @@ fn build_filter_plugin_table(filter_plugins: &Vec<String>) -> Table {
b->"Description"));
// Sort plugins by name
let mut sorted_plugin_names = filter_plugins.clone();
sorted_plugin_names.sort();
let mut sorted_plugins = filter_plugins.clone();
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();
// Format options as YAML string
let options_str = if options.is_empty() {
"{}".to_string()
} else {
let options_map: std::collections::BTreeMap<_, _> = options
.iter()
.map(|opt| (opt.name.clone(), serde_yaml::to_value(opt).unwrap()))
.collect();
serde_yaml::to_string(&options_map)
.unwrap_or_else(|_| "Unable to serialize options".to_string())
.trim()
.to_string()
};
for plugin_info in sorted_plugins {
// Format options as YAML string
let options_str = if plugin_info.options.is_empty() {
"{}".to_string()
} else {
// Convert options to a map for better display
let options_map: std::collections::BTreeMap<_, _> = plugin_info.options
.iter()
.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();
serde_yaml::to_string(&options_map)
.unwrap_or_else(|_| "Unable to serialize options".to_string())
.trim()
.to_string()
};
// Use a default description
let description = "Filter plugin".to_string();
filter_plugin_table.add_row(Row::new(vec![
Cell::new(&plugin_name),
Cell::new(&options_str),
Cell::new(&description),
]));
}
filter_plugin_table.add_row(Row::new(vec![
Cell::new(&plugin_info.name),
Cell::new(&options_str),
Cell::new(&plugin_info.description),
]));
}
// If no filter plugins are available, add a row indicating that