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:
@@ -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
|
||||||
|
.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()
|
||||||
|
};
|
||||||
|
|
||||||
// Get options
|
filter_plugin_table.add_row(Row::new(vec![
|
||||||
let options = plugin.options();
|
Cell::new(&plugin_info.name),
|
||||||
|
Cell::new(&options_str),
|
||||||
// Format options as YAML string
|
Cell::new(&plugin_info.description),
|
||||||
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()
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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),
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no filter plugins are available, add a row indicating that
|
// If no filter plugins are available, add a row indicating that
|
||||||
|
|||||||
Reference in New Issue
Block a user