refactor: remove META_PLUGIN_PROGRAMS and use get_meta_plugin() instead
Co-authored-by: aider (openai/andrew.openrouter.qwen.qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
extern crate enum_map;
|
|
||||||
use enum_map::enum_map;
|
|
||||||
use enum_map::{Enum, EnumMap};
|
|
||||||
|
|
||||||
pub mod program;
|
pub mod program;
|
||||||
pub mod digest;
|
pub mod digest;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
@@ -15,7 +9,7 @@ use crate::meta_plugin::program::MetaPluginProgram;
|
|||||||
use crate::meta_plugin::digest::{DigestSha256MetaPlugin, ReadTimeMetaPlugin, ReadRateMetaPlugin};
|
use crate::meta_plugin::digest::{DigestSha256MetaPlugin, ReadTimeMetaPlugin, ReadRateMetaPlugin};
|
||||||
use crate::meta_plugin::system::{CwdMetaPlugin, UidMetaPlugin, UserMetaPlugin, GidMetaPlugin, GroupMetaPlugin, ShellMetaPlugin, ShellPidMetaPlugin, KeepPidMetaPlugin, HostnameMetaPlugin, FullHostnameMetaPlugin};
|
use crate::meta_plugin::system::{CwdMetaPlugin, UidMetaPlugin, UserMetaPlugin, GidMetaPlugin, GroupMetaPlugin, ShellMetaPlugin, ShellPidMetaPlugin, KeepPidMetaPlugin, HostnameMetaPlugin, FullHostnameMetaPlugin};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString, Enum)]
|
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString)]
|
||||||
#[strum(ascii_case_insensitive)]
|
#[strum(ascii_case_insensitive)]
|
||||||
pub enum MetaPluginType {
|
pub enum MetaPluginType {
|
||||||
FileMagic,
|
FileMagic,
|
||||||
@@ -54,51 +48,6 @@ pub trait MetaPlugin {
|
|||||||
|
|
||||||
use std::io::Write;
|
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(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::FileMime => {
|
|
||||||
let program = MetaPluginProgram::new("file", vec!["-b", "--mime-type", "-"], "file_mime".to_string(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::FileEncoding => {
|
|
||||||
let program = MetaPluginProgram::new("file", vec!["-b", "--mime-encoding", "-"], "file_encoding".to_string(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::LineCount => {
|
|
||||||
let program = MetaPluginProgram::new("wc", vec!["-l"], "line_count".to_string(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::WordCount => {
|
|
||||||
let program = MetaPluginProgram::new("wc", vec!["-w"], "word_count".to_string(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::Cwd => None,
|
|
||||||
MetaPluginType::Uid => None,
|
|
||||||
MetaPluginType::User => None,
|
|
||||||
MetaPluginType::Gid => None,
|
|
||||||
MetaPluginType::Group => None,
|
|
||||||
MetaPluginType::Shell => None,
|
|
||||||
MetaPluginType::ShellPid => None,
|
|
||||||
MetaPluginType::KeepPid => 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(), true);
|
|
||||||
if program.supported { Some(program) } else { None }
|
|
||||||
}
|
|
||||||
MetaPluginType::ReadTime => None,
|
|
||||||
MetaPluginType::ReadRate => None,
|
|
||||||
MetaPluginType::Hostname => None,
|
|
||||||
MetaPluginType::FullHostname => None,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {
|
||||||
match meta_plugin_type {
|
match meta_plugin_type {
|
||||||
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)),
|
MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"], "file_magic".to_string(), true)),
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ use prettytable::row;
|
|||||||
use prettytable::{Attr, Cell, Row, Table};
|
use prettytable::{Attr, Cell, Row, Table};
|
||||||
|
|
||||||
use crate::meta_plugin;
|
use crate::meta_plugin;
|
||||||
use crate::meta_plugin::META_PLUGIN_PROGRAMS;
|
|
||||||
use crate::meta_plugin::MetaPluginType;
|
use crate::meta_plugin::MetaPluginType;
|
||||||
use crate::meta_plugin::program::MetaPluginProgram;
|
use crate::meta_plugin::get_meta_plugin;
|
||||||
|
|
||||||
fn build_path_table(data_path: PathBuf, db_path: PathBuf) -> Table {
|
fn build_path_table(data_path: PathBuf, db_path: PathBuf) -> Table {
|
||||||
let mut path_table = Table::new();
|
let mut path_table = Table::new();
|
||||||
@@ -133,27 +132,46 @@ fn build_meta_plugin_table(enabled_meta_plugins: &Vec<MetaPluginType>) -> Table
|
|||||||
let is_supported = meta_plugin.is_supported();
|
let is_supported = meta_plugin.is_supported();
|
||||||
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
|
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
|
||||||
|
|
||||||
// Get program info for display purposes
|
|
||||||
let meta_plugin_program: Option<MetaPluginProgram> = META_PLUGIN_PROGRAMS[meta_plugin_type.clone()].clone();
|
|
||||||
|
|
||||||
// Determine what implementation will actually be used
|
// Determine what implementation will actually be used
|
||||||
let (binary_display, args_display) = match meta_plugin_type {
|
let (binary_display, args_display) = match meta_plugin_type {
|
||||||
// For internal plugins, always show as internal
|
// For internal plugins, always show as internal
|
||||||
MetaPluginType::DigestSha256 | MetaPluginType::ReadTime | MetaPluginType::ReadRate => {
|
MetaPluginType::DigestSha256 | MetaPluginType::ReadTime | MetaPluginType::ReadRate |
|
||||||
|
MetaPluginType::Cwd | MetaPluginType::Uid | MetaPluginType::User |
|
||||||
|
MetaPluginType::Gid | MetaPluginType::Group | MetaPluginType::Shell |
|
||||||
|
MetaPluginType::ShellPid | MetaPluginType::KeepPid | MetaPluginType::Hostname |
|
||||||
|
MetaPluginType::FullHostname => {
|
||||||
("<INTERNAL>".to_string(), "".to_string())
|
("<INTERNAL>".to_string(), "".to_string())
|
||||||
},
|
},
|
||||||
// For program-based plugins, show program info if supported, otherwise show as not found
|
// For program-based plugins, show program info if supported, otherwise show as not found
|
||||||
_ => {
|
_ => {
|
||||||
match &meta_plugin_program {
|
// For program-based plugins, we need to check if they're supported
|
||||||
Some(program) => {
|
if is_supported {
|
||||||
if program.supported {
|
// Get the program info by downcasting to MetaPluginProgram
|
||||||
(program.program.clone(), program.args.join(" "))
|
// 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())
|
||||||
} else {
|
} else {
|
||||||
("<NOT FOUND>".to_string(), "".to_string())
|
("<NOT FOUND>".to_string(), "".to_string())
|
||||||
}
|
}
|
||||||
},
|
|
||||||
None => ("<INTERNAL>".to_string(), "".to_string()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user