refactor: remove unused MetaPluginType::None and related code
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
08001aa2d0
commit
25e41c46a9
@@ -126,7 +126,7 @@ struct ItemArgs {
|
|||||||
#[arg(help("Compression algorithm to use when saving items"))]
|
#[arg(help("Compression algorithm to use when saving items"))]
|
||||||
compression: Option<String>,
|
compression: Option<String>,
|
||||||
|
|
||||||
#[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"))]
|
#[arg(help("Meta plugins to use when saving items"))]
|
||||||
meta_plugins: Vec<String>,
|
meta_plugins: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ extern crate enum_map;
|
|||||||
use enum_map::enum_map;
|
use enum_map::enum_map;
|
||||||
use enum_map::{Enum, EnumMap};
|
use enum_map::{Enum, EnumMap};
|
||||||
|
|
||||||
pub mod none;
|
|
||||||
pub mod program;
|
pub mod program;
|
||||||
|
|
||||||
use crate::meta_plugin::none::MetaPluginNone;
|
|
||||||
use crate::meta_plugin::program::MetaPluginProgram;
|
use crate::meta_plugin::program::MetaPluginProgram;
|
||||||
|
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
@@ -18,8 +16,7 @@ use strum::IntoEnumIterator;
|
|||||||
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString, Enum)]
|
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString, Enum)]
|
||||||
#[strum(ascii_case_insensitive)]
|
#[strum(ascii_case_insensitive)]
|
||||||
pub enum MetaPluginType {
|
pub enum MetaPluginType {
|
||||||
FileMagic,
|
FileMagic
|
||||||
None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MetaPlugin {
|
pub trait MetaPlugin {
|
||||||
@@ -41,25 +38,11 @@ lazy_static! {
|
|||||||
let program = MetaPluginProgram::new("file", vec!["-bE", "-"]);
|
let program = MetaPluginProgram::new("file", vec!["-bE", "-"]);
|
||||||
if program.supported { Some(program) } else { None }
|
if program.supported { Some(program) } else { None }
|
||||||
}
|
}
|
||||||
MetaPluginType::None => 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", "-"])),
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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<Box<dyn Write>> {
|
|
||||||
Ok(Box::new(DummyWriter::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finalize(&mut self) -> io::Result<String> {
|
|
||||||
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<usize> {
|
|
||||||
Ok(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -180,12 +180,9 @@ fn build_meta_plugin_table() -> Table {
|
|||||||
meta_plugin_table.set_titles(row!(
|
meta_plugin_table.set_titles(row!(
|
||||||
b->"Type",
|
b->"Type",
|
||||||
b->"Found",
|
b->"Found",
|
||||||
b->"Default",
|
|
||||||
b->"Binary",
|
b->"Binary",
|
||||||
b->"Args"));
|
b->"Args"));
|
||||||
|
|
||||||
let default_type = meta_plugin::default_meta_plugin_type();
|
|
||||||
|
|
||||||
for meta_plugin_type in MetaPluginType::iter() {
|
for meta_plugin_type in MetaPluginType::iter() {
|
||||||
let meta_plugin_program: MetaPluginProgram = match &META_PLUGIN_PROGRAMS[meta_plugin_type.clone()] {
|
let meta_plugin_program: MetaPluginProgram = match &META_PLUGIN_PROGRAMS[meta_plugin_type.clone()] {
|
||||||
Some(meta_plugin_program) => meta_plugin_program.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![
|
meta_plugin_table.add_row(Row::new(vec![
|
||||||
Cell::new(&meta_plugin_type.to_string()),
|
Cell::new(&meta_plugin_type.to_string()),
|
||||||
match meta_plugin_program.supported {
|
match meta_plugin_program.supported {
|
||||||
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
|
true => Cell::new("Yes").with_style(Attr::ForegroundColor(color::GREEN)),
|
||||||
false => Cell::new("No").with_style(Attr::ForegroundColor(color::RED)),
|
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() {
|
match meta_plugin_program.program.is_empty() {
|
||||||
true => {
|
true => {
|
||||||
Cell::new("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
|
Cell::new("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
|
||||||
|
|||||||
Reference in New Issue
Block a user