refactor: remove is_default from meta plugins and add read_time/read_rate plugins
Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -21,6 +21,8 @@ pub enum MetaPluginType {
|
||||
FileMagic,
|
||||
DigestSha256,
|
||||
DigestMd5,
|
||||
ReadTime,
|
||||
ReadRate,
|
||||
}
|
||||
|
||||
pub trait MetaPlugin {
|
||||
@@ -34,10 +36,6 @@ pub trait MetaPlugin {
|
||||
fn update(&mut self, data: &[u8]);
|
||||
|
||||
fn meta_name(&mut self) -> String;
|
||||
|
||||
fn is_default(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
use std::io::Write;
|
||||
@@ -48,9 +46,12 @@ lazy_static! {
|
||||
let program = MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true);
|
||||
if program.supported { Some(program) } else { None }
|
||||
}
|
||||
MetaPluginType::DigestSha256 => None,
|
||||
MetaPluginType::DigestSha256 => {
|
||||
let program = MetaPluginProgram::new("sha256sum", vec![], "digest_sha256".to_string(), true);
|
||||
if program.supported { Some(program) } else { None }
|
||||
}
|
||||
MetaPluginType::DigestMd5 => {
|
||||
let program = MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), false);
|
||||
let program = MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), true);
|
||||
if program.supported { Some(program) } else { None }
|
||||
}
|
||||
};
|
||||
@@ -60,7 +61,9 @@ pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin>
|
||||
match meta_plugin_type {
|
||||
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)),
|
||||
MetaPluginType::DigestSha256 => Box::new(DigestSha256MetaPlugin::new()),
|
||||
MetaPluginType::DigestMd5 => Box::new(MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), false)),
|
||||
MetaPluginType::DigestMd5 => Box::new(MetaPluginProgram::new("md5sum", vec![], "digest_md5".to_string(), true)),
|
||||
MetaPluginType::ReadTime => Box::new(ReadTimeMetaPlugin::new()),
|
||||
MetaPluginType::ReadRate => Box::new(ReadRateMetaPlugin::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,6 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
fn is_default(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy writer that implements Write but doesn't do anything
|
||||
|
||||
@@ -16,12 +16,12 @@ pub struct MetaPluginProgram {
|
||||
pub args: Vec<String>,
|
||||
pub supported: bool,
|
||||
pub meta_name: String,
|
||||
pub is_default: bool,
|
||||
pub split_whitespace: bool,
|
||||
buffer: Vec<u8>,
|
||||
}
|
||||
|
||||
impl MetaPluginProgram {
|
||||
pub fn new(program: &str, args: Vec<&str>, meta_name: String, is_default: bool) -> MetaPluginProgram {
|
||||
pub fn new(program: &str, args: Vec<&str>, meta_name: String, split_whitespace: bool) -> MetaPluginProgram {
|
||||
let program_path = get_program_path(program);
|
||||
let supported = program_path.is_ok();
|
||||
|
||||
@@ -30,7 +30,7 @@ impl MetaPluginProgram {
|
||||
args: args.iter().map(|s| s.to_string()).collect(),
|
||||
supported,
|
||||
meta_name,
|
||||
is_default,
|
||||
split_whitespace,
|
||||
buffer: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,8 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let trimmed_result = stdout.trim();
|
||||
|
||||
// For certain programs like md5sum, we only want the first part before whitespace
|
||||
if self.program.ends_with("sum") {
|
||||
// For certain programs, we only want the first part before whitespace
|
||||
if self.split_whitespace {
|
||||
let parts: Vec<&str> = trimmed_result.split_whitespace().collect();
|
||||
if !parts.is_empty() {
|
||||
Ok(parts[0].to_string())
|
||||
@@ -118,9 +118,6 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
self.meta_name.clone()
|
||||
}
|
||||
|
||||
fn is_default(&self) -> bool {
|
||||
self.is_default
|
||||
}
|
||||
}
|
||||
|
||||
fn get_program_path(program: &str) -> Result<String> {
|
||||
|
||||
Reference in New Issue
Block a user