feat: add program plugin for running ad-hoc commands
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -120,12 +120,7 @@ impl MetaPlugin for BaseMetaPlugin {
|
||||
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString)]
|
||||
#[strum(serialize_all = "snake_case", ascii_case_insensitive)]
|
||||
pub enum MetaPluginType {
|
||||
FileMagic,
|
||||
FileMime,
|
||||
FileEncoding,
|
||||
MagicFile,
|
||||
LineCount,
|
||||
WordCount,
|
||||
Cwd,
|
||||
Binary,
|
||||
Text,
|
||||
@@ -137,6 +132,7 @@ pub enum MetaPluginType {
|
||||
ReadTime,
|
||||
ReadRate,
|
||||
Hostname,
|
||||
Program,
|
||||
}
|
||||
|
||||
/// Central function to handle metadata output with name mapping
|
||||
@@ -282,12 +278,7 @@ pub fn get_meta_plugin(
|
||||
outputs: Option<std::collections::HashMap<String, serde_yaml::Value>>,
|
||||
) -> Box<dyn MetaPlugin> {
|
||||
match meta_plugin_type {
|
||||
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true, options, outputs)),
|
||||
MetaPluginType::FileMime => Box::new(MetaPluginProgram::new("file", vec!["-b", "--mime-type", "-"], "file_mime".to_string(), true, options, outputs)),
|
||||
MetaPluginType::FileEncoding => Box::new(MetaPluginProgram::new("file", vec!["-b", "--mime-encoding", "-"], "file_encoding".to_string(), true, options, outputs)),
|
||||
MetaPluginType::MagicFile => Box::new(MagicFileMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::LineCount => Box::new(MetaPluginProgram::new("wc", vec!["-l"], "line_count".to_string(), true, options, outputs)),
|
||||
MetaPluginType::WordCount => Box::new(MetaPluginProgram::new("wc", vec!["-w"], "word_count".to_string(), true, options, outputs)),
|
||||
MetaPluginType::Cwd => Box::new(CwdMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::Binary => Box::new(BinaryMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::Text => Box::new(TextMetaPlugin::new(options, outputs)),
|
||||
@@ -299,5 +290,42 @@ pub fn get_meta_plugin(
|
||||
MetaPluginType::ReadTime => Box::new(ReadTimeMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::Hostname => Box::new(HostnameMetaPlugin::new(options, outputs)),
|
||||
MetaPluginType::Program => {
|
||||
// For program type, we need to parse the command from options
|
||||
let mut program_name = String::new();
|
||||
let mut args = Vec::new();
|
||||
let mut meta_name = "program".to_string();
|
||||
let mut split_whitespace = true;
|
||||
|
||||
if let Some(opts) = &options {
|
||||
if let Some(command_value) = opts.get("command") {
|
||||
if let Some(command_str) = command_value.as_str() {
|
||||
let parts: Vec<&str> = command_str.split_whitespace().collect();
|
||||
if !parts.is_empty() {
|
||||
program_name = parts[0].to_string();
|
||||
args = parts[1..].iter().map(|s| s.to_string()).collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Handle other options if needed
|
||||
if let Some(split_value) = opts.get("split_whitespace") {
|
||||
if let Some(split_bool) = split_value.as_bool() {
|
||||
split_whitespace = split_bool;
|
||||
}
|
||||
}
|
||||
if let Some(name_value) = opts.get("name") {
|
||||
if let Some(name_str) = name_value.as_str() {
|
||||
meta_name = name_str.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Box::new(MetaPluginProgram::new(&program_name,
|
||||
args.iter().map(|s| s.as_str()).collect(),
|
||||
meta_name,
|
||||
split_whitespace,
|
||||
options,
|
||||
outputs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user