From 25e41c46a97a1c63448db7193b9e6ea69d76eb9e Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Thu, 22 May 2025 13:21:10 -0300 Subject: [PATCH] refactor: remove unused MetaPluginType::None and related code --- src/main.rs | 2 +- src/meta_plugin.rs | 19 +----------------- src/meta_plugin/none.rs | 43 ----------------------------------------- src/modes/status.rs | 9 --------- 4 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 src/meta_plugin/none.rs diff --git a/src/main.rs b/src/main.rs index a9b5321..b2f1de0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,7 +126,7 @@ struct ItemArgs { #[arg(help("Compression algorithm to use when saving items"))] compression: Option, - #[arg(help_heading("Item Options"), short, long, env("KEEP_META_PLUGINS"))] + #[arg(help_heading("Item Options"), short('M'), long, env("KEEP_META_PLUGINS"))] #[arg(help("Meta plugins to use when saving items"))] meta_plugins: Vec, } diff --git a/src/meta_plugin.rs b/src/meta_plugin.rs index 5b1a390..a8b7952 100644 --- a/src/meta_plugin.rs +++ b/src/meta_plugin.rs @@ -7,10 +7,8 @@ extern crate enum_map; use enum_map::enum_map; use enum_map::{Enum, EnumMap}; -pub mod none; pub mod program; -use crate::meta_plugin::none::MetaPluginNone; use crate::meta_plugin::program::MetaPluginProgram; use strum::IntoEnumIterator; @@ -18,8 +16,7 @@ use strum::IntoEnumIterator; #[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString, Enum)] #[strum(ascii_case_insensitive)] pub enum MetaPluginType { - FileMagic, - None, + FileMagic } pub trait MetaPlugin { @@ -41,25 +38,11 @@ lazy_static! { let program = MetaPluginProgram::new("file", vec!["-bE", "-"]); if program.supported { Some(program) } else { None } } - MetaPluginType::None => None }; } pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box { match meta_plugin_type { MetaPluginType::FileMagic => Box::new(MetaPluginProgram::new("file", vec!["-bE", "-"])), - MetaPluginType::None => Box::new(MetaPluginNone::new()), } } - -pub fn default_meta_plugin_type() -> MetaPluginType { - let mut default = MetaPluginType::None; - for meta_plugin_type in MetaPluginType::iter() { - let meta_plugin = get_meta_plugin(meta_plugin_type.clone()); - if meta_plugin.is_supported() { - default = meta_plugin_type; - break; - } - } - default -} diff --git a/src/meta_plugin/none.rs b/src/meta_plugin/none.rs deleted file mode 100644 index 60bb2ec..0000000 --- a/src/meta_plugin/none.rs +++ /dev/null @@ -1,43 +0,0 @@ -use anyhow::Result; -use log::*; -use std::io::{self, Write}; - -#[derive(Debug, Eq, PartialEq, Clone, Default)] -pub struct MetaPluginNone {} - -impl MetaPluginNone { - pub fn new() -> MetaPluginNone { - MetaPluginNone {} - } -} - -impl MetaPlugin for MetaPluginNone { - fn create(&self) -> Result> { - Ok(Box::new(DummyWriter::new())) - } - - fn finalize(&mut self) -> io::Result { - Ok("none".to_string()) - } - - fn update(&mut self, _data: &[u8]) {} -} - -// Dummy writer that implements Write for the none meta plugin -struct DummyWriter; - -impl DummyWriter { - fn new() -> Self { - DummyWriter - } -} - -impl Write for DummyWriter { - fn write(&mut self, _buf: &[u8]) -> io::Result { - Ok(0) - } - - fn flush(&mut self) -> io::Result<()> { - Ok(()) - } -} diff --git a/src/modes/status.rs b/src/modes/status.rs index f35c36a..2ab717c 100644 --- a/src/modes/status.rs +++ b/src/modes/status.rs @@ -180,12 +180,9 @@ fn build_meta_plugin_table() -> Table { meta_plugin_table.set_titles(row!( b->"Type", b->"Found", - b->"Default", b->"Binary", b->"Args")); - let default_type = meta_plugin::default_meta_plugin_type(); - for meta_plugin_type in MetaPluginType::iter() { let meta_plugin_program: MetaPluginProgram = match &META_PLUGIN_PROGRAMS[meta_plugin_type.clone()] { Some(meta_plugin_program) => meta_plugin_program.clone(), @@ -196,18 +193,12 @@ fn build_meta_plugin_table() -> Table { }, }; - let is_default = meta_plugin_type == default_type; - meta_plugin_table.add_row(Row::new(vec![ Cell::new(&meta_plugin_type.to_string()), match meta_plugin_program.supported { true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)), false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)), }, - match is_default { - true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)), - false => Cell::new("No"), - }, match meta_plugin_program.program.is_empty() { true => { Cell::new("").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))