feat: add is_default method to MetaPlugin and MetaPluginProgram
This commit is contained in:
@@ -30,6 +30,10 @@ 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;
|
||||
@@ -37,7 +41,7 @@ use std::io::Write;
|
||||
lazy_static! {
|
||||
pub static ref META_PLUGIN_PROGRAMS: EnumMap<MetaPluginType, Option<MetaPluginProgram>> = enum_map! {
|
||||
MetaPluginType::FileMagic => {
|
||||
let program = MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string());
|
||||
let program = MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true);
|
||||
if program.supported { Some(program) } else { None }
|
||||
}
|
||||
};
|
||||
@@ -45,7 +49,7 @@ lazy_static! {
|
||||
|
||||
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())),
|
||||
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@ pub struct MetaPluginProgram {
|
||||
pub args: Vec<String>,
|
||||
pub supported: bool,
|
||||
pub meta_name: String,
|
||||
pub is_default: bool,
|
||||
}
|
||||
|
||||
impl MetaPluginProgram {
|
||||
pub fn new(program: &str, args: Vec<&str>, meta_name: String) -> MetaPluginProgram {
|
||||
pub fn new(program: &str, args: Vec<&str>, meta_name: String, is_default: bool) -> MetaPluginProgram {
|
||||
let program_path = get_program_path(program);
|
||||
let supported = program_path.is_ok();
|
||||
|
||||
@@ -28,6 +29,7 @@ impl MetaPluginProgram {
|
||||
args: args.iter().map(|s| s.to_string()).collect(),
|
||||
supported,
|
||||
meta_name,
|
||||
is_default,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +74,10 @@ impl MetaPlugin for MetaPluginProgram {
|
||||
fn meta_name(&mut self) -> String {
|
||||
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