From b90400a1c727b4273665cf430e3e735d7c82ceb2 Mon Sep 17 00:00:00 2001 From: Abraham Toriz Date: Mon, 6 Sep 2021 20:53:18 -0500 Subject: [PATCH] pass formatter config to formatter --- src/formatters/custom.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/formatters/custom.rs b/src/formatters/custom.rs index 84c17e3..baa51ae 100644 --- a/src/formatters/custom.rs +++ b/src/formatters/custom.rs @@ -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 { @@ -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(formatter: &str, entries: Vec, 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);