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,42 +136,38 @@ 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 { for plugin_info in sorted_plugins {
// Get the plugin creator // Format options as YAML string
let filter_plugins_map = get_available_filter_plugins(); let options_str = if plugin_info.options.is_empty() {
if let Some(plugin_creator) = filter_plugins_map.get(&plugin_name) { "{}".to_string()
// Create a temporary instance to get options } else {
let plugin = plugin_creator(); // Convert options to a map for better display
let options_map: std::collections::BTreeMap<_, _> = plugin_info.options
// Get options .iter()
let options = plugin.options(); .map(|opt| {
let mut opt_map = std::collections::BTreeMap::new();
// Format options as YAML string opt_map.insert("name", &opt.name);
let options_str = if options.is_empty() { if let Some(default) = &opt.default {
"{}".to_string() opt_map.insert("default", default);
} else { }
let options_map: std::collections::BTreeMap<_, _> = options opt_map.insert("required", &opt.required);
.iter() (opt.name.clone(), serde_yaml::Value::String(format!("{:?}", opt_map)))
.map(|opt| (opt.name.clone(), serde_yaml::to_value(opt).unwrap())) })
.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())
.trim() .trim()
.to_string() .to_string()
}; };
// Use a default description filter_plugin_table.add_row(Row::new(vec![
let description = "Filter plugin".to_string(); Cell::new(&plugin_info.name),
Cell::new(&options_str),
filter_plugin_table.add_row(Row::new(vec![ Cell::new(&plugin_info.description),
Cell::new(&plugin_name), ]));
Cell::new(&options_str),
Cell::new(&description),
]));
}
} }
// If no filter plugins are available, add a row indicating that // If no filter plugins are available, add a row indicating that