diff --git a/src/meta_plugin.rs b/src/meta_plugin.rs index e96696e..fd61ad5 100644 --- a/src/meta_plugin.rs +++ b/src/meta_plugin.rs @@ -37,6 +37,7 @@ pub trait MetaPlugin { fn is_supported(&self) -> bool { true } + fn create(&self) -> Result>; fn finalize(&mut self) -> io::Result; @@ -44,6 +45,11 @@ pub trait MetaPlugin { fn update(&mut self, data: &[u8]); fn meta_name(&mut self) -> String; + + // Get program information for display in status + fn program_info(&self) -> Option<(&str, Vec<&str>)> { + None + } } use std::io::Write; diff --git a/src/meta_plugin/program.rs b/src/meta_plugin/program.rs index b43d3a7..5ef27c1 100644 --- a/src/meta_plugin/program.rs +++ b/src/meta_plugin/program.rs @@ -117,6 +117,14 @@ impl MetaPlugin for MetaPluginProgram { fn meta_name(&mut self) -> String { self.meta_name.clone() } + + fn program_info(&self) -> Option<(&str, Vec<&str>)> { + if self.supported { + Some((&self.program, self.args.iter().map(|s| s.as_str()).collect())) + } else { + None + } + } } diff --git a/src/modes/status.rs b/src/modes/status.rs index 6f3f43e..13b59e4 100644 --- a/src/modes/status.rs +++ b/src/modes/status.rs @@ -147,29 +147,12 @@ fn build_meta_plugin_table(enabled_meta_plugins: &Vec) -> Table }, // For program-based plugins, show program info _ => { - // Get the program info by downcasting to MetaPluginProgram - // This is a bit hacky but necessary to get the program info - let program_name = match meta_plugin_type { - MetaPluginType::FileMagic => "file".to_string(), - MetaPluginType::FileMime => "file".to_string(), - MetaPluginType::FileEncoding => "file".to_string(), - MetaPluginType::LineCount => "wc".to_string(), - MetaPluginType::WordCount => "wc".to_string(), - MetaPluginType::DigestMd5 => "md5sum".to_string(), - _ => "".to_string(), - }; - - let args = match meta_plugin_type { - MetaPluginType::FileMagic => "-bE -", - MetaPluginType::FileMime => "-b --mime-type -", - MetaPluginType::FileEncoding => "-b --mime-encoding -", - MetaPluginType::LineCount => "-l", - MetaPluginType::WordCount => "-w", - MetaPluginType::DigestMd5 => "", - _ => "", - }; - - (program_name, args.to_string()) + // Get program info from the meta plugin itself + if let Some((program, args)) = meta_plugin.program_info() { + (program.to_string(), args.join(" ")) + } else { + ("".to_string(), "".to_string()) + } } } };