use std::collections::HashMap;
use bole::pm::{GroupedPmInfo, PmInfo, Tool};
pub(crate) mod csv;
pub(crate) mod json;
pub(crate) mod table;
pub(crate) mod tree;
#[derive(Debug, Clone, Copy)]
pub(crate) enum Format {
Json,
Csv,
Table,
Tree,
}
pub(crate) trait Formatter {
fn format_pms(&self, pms: &[PmInfo]) -> String;
fn format_grouped(&self, grouped: &[GroupedPmInfo]) -> String;
#[allow(dead_code)]
fn format_tools(&self, tools: &HashMap<String, Vec<Tool>>) -> String;
}
impl Format {
pub(crate) fn from_flags(json: bool, csv: bool, tree: bool) -> Self {
match (json, csv, tree) {
(true, _, _) => Self::Json,
(_, true, _) => Self::Csv,
(_, _, true) => Self::Tree,
_ => Self::Table,
}
}
}
impl Formatter for Format {
fn format_pms(&self, pms: &[PmInfo]) -> String {
match self {
Self::Json => json::JsonFormatter.format_pms(pms),
Self::Csv => csv::CsvFormatter.format_pms(pms),
Self::Table => table::TableFormatter.format_pms(pms),
Self::Tree => tree::TreeFormatter.format_pms(pms),
}
}
fn format_grouped(&self, grouped: &[GroupedPmInfo]) -> String {
match self {
Self::Json => json::JsonFormatter.format_grouped(grouped),
Self::Csv => csv::CsvFormatter.format_grouped(grouped),
Self::Table => table::TableFormatter.format_grouped(grouped),
Self::Tree => tree::TreeFormatter.format_grouped(grouped),
}
}
fn format_tools(&self, tools: &HashMap<String, Vec<Tool>>) -> String {
match self {
Self::Json => json::JsonFormatter.format_tools(tools),
Self::Csv => csv::CsvFormatter.format_tools(tools),
Self::Table => table::TableFormatter.format_tools(tools),
Self::Tree => tree::TreeFormatter.format_tools(tools),
}
}
}