pass formatter config to formatter
This commit is contained in:
parent
d3128a93bf
commit
b90400a1c7
|
@ -9,6 +9,7 @@ use chrono::SecondsFormat;
|
||||||
use crate::error::{Result, Error::*};
|
use crate::error::{Result, Error::*};
|
||||||
use crate::models::Entry;
|
use crate::models::Entry;
|
||||||
use crate::commands::Facts;
|
use crate::commands::Facts;
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
/// tries to find a formatter with the given name in one of the possible paths
|
/// tries to find a formatter with the given name in one of the possible paths
|
||||||
fn formatter_path(formatters: &[PathBuf], name: &str) -> Option<PathBuf> {
|
fn formatter_path(formatters: &[PathBuf], name: &str) -> Option<PathBuf> {
|
||||||
|
@ -31,6 +32,18 @@ fn is_valid_formatter_name(formatter: &str) -> bool {
|
||||||
}).count() == 0
|
}).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<()>
|
pub fn print_formatted<O, E>(formatter: &str, entries: Vec<Entry>, out: &mut O, err: &mut E, facts: &Facts) -> Result<()>
|
||||||
where
|
where
|
||||||
O: Write,
|
O: Write,
|
||||||
|
@ -50,7 +63,7 @@ where
|
||||||
config_at: facts.config.path.clone().unwrap_or_else(|| "in memory".into()),
|
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);
|
let mut command = Command::new(&path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue