pass formatter config to formatter

This commit is contained in:
Abraham Toriz 2021-09-06 20:53:18 -05:00
parent d3128a93bf
commit b90400a1c7
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 14 additions and 1 deletions

View File

@ -9,6 +9,7 @@ use chrono::SecondsFormat;
use crate::error::{Result, Error::*};
use crate::models::Entry;
use crate::commands::Facts;
use crate::config::Config;
/// tries to find a formatter with the given name in one of the possible paths
fn formatter_path(formatters: &[PathBuf], name: &str) -> Option<PathBuf> {
@ -31,6 +32,18 @@ fn is_valid_formatter_name(formatter: &str) -> bool {
}).count() == 0
}
fn get_formatter_config(config: &Config, formatter: &str) -> String {
if let Some(formatters) = config.extra.get("formatters") {
if let Some(config_for_formatter) = formatters.get(formatter) {
config_for_formatter.to_string()
} else {
String::from("{}")
}
} else {
String::from("{}")
}
}
pub fn print_formatted<O, E>(formatter: &str, entries: Vec<Entry>, out: &mut O, err: &mut E, facts: &Facts) -> Result<()>
where
O: Write,
@ -50,7 +63,7 @@ where
config_at: facts.config.path.clone().unwrap_or_else(|| "in memory".into()),
})?;
let config = "{}";
let config = get_formatter_config(&facts.config, formatter);
let mut command = Command::new(&path);