feat: add meta plugins table to status mode
This commit is contained in:
@@ -14,6 +14,11 @@ use prettytable::color;
|
||||
use prettytable::row;
|
||||
use prettytable::{Attr, Cell, Row, Table};
|
||||
|
||||
use crate::meta_plugin;
|
||||
use crate::meta_plugin::META_PLUGIN_PROGRAMS;
|
||||
use crate::meta_plugin::MetaPluginType;
|
||||
use crate::meta_plugin::program::MetaPluginProgram;
|
||||
|
||||
fn build_path_table(data_path: PathBuf, db_path: PathBuf) -> Table {
|
||||
let mut path_table = Table::new();
|
||||
|
||||
@@ -164,6 +169,58 @@ fn build_digest_table() -> Table {
|
||||
digest_table
|
||||
}
|
||||
|
||||
fn build_meta_plugin_table() -> Table {
|
||||
let mut meta_plugin_table = Table::new();
|
||||
if std::io::stdout().is_terminal() {
|
||||
meta_plugin_table.set_format(*FORMAT_BOX_CHARS_NO_BORDER_LINE_SEPARATOR);
|
||||
} else {
|
||||
meta_plugin_table.set_format(*FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
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(),
|
||||
None => MetaPluginProgram {
|
||||
program: "".to_string(),
|
||||
args: Vec::new(),
|
||||
supported: true,
|
||||
},
|
||||
};
|
||||
|
||||
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("<INTERNAL>").with_style(Attr::ForegroundColor(color::BRIGHT_BLACK))
|
||||
}
|
||||
false => Cell::new(&meta_plugin_program.program),
|
||||
},
|
||||
Cell::new(&meta_plugin_program.args.join(" ")),
|
||||
]));
|
||||
}
|
||||
|
||||
meta_plugin_table
|
||||
}
|
||||
|
||||
pub fn mode_status(
|
||||
_cmd: &mut Command,
|
||||
_args: &crate::Args,
|
||||
@@ -178,5 +235,8 @@ pub fn mode_status(
|
||||
println!();
|
||||
println!("DIGEST:");
|
||||
build_digest_table().printstd();
|
||||
println!();
|
||||
println!("META PLUGINS:");
|
||||
build_meta_plugin_table().printstd();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user