From 97f2678563e6ca997ea33d7befe38ab2acfa01a9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 14 Dec 2019 03:23:46 +0100 Subject: add preliminary support for user configurations --- src/main.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 395e683..f990319 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ extern crate num_traits; extern crate reqwest; extern crate rusttype; extern crate termcolor; +extern crate toml; extern crate xdg; #[macro_use] extern crate lazy_static; @@ -33,6 +34,7 @@ mod bt; mod cache; mod output; mod render; +mod useropts; use clap::{App, Arg, ArgMatches}; @@ -345,6 +347,12 @@ fn run() -> MainResult<()> { .default_value("buildtemplate.png") .takes_value(true), ) + .arg( + Arg::with_name("config") + .help("Specifies the render option file.") + .long("config") + .takes_value(true), + ) .get_matches(); let mut api = Api::new(cache::FileCache::new()); @@ -360,7 +368,13 @@ fn run() -> MainResult<()> { println!("{}", build.chatlink()); } - let mut renderer = render::Renderer::new(&mut api, Default::default()); + let render_options = if let Some(config_path) = matches.value_of("config") { + useropts::load_file(config_path)? + } else { + Default::default() + }; + + let mut renderer = render::Renderer::new(&mut api, render_options); match renderer.render_buildtemplate(&build) { Ok(img) => { let filename = matches.value_of("outfile").unwrap(); @@ -368,7 +382,7 @@ fn run() -> MainResult<()> { if !matches.is_present("quiet") { println!("Image saved in {}", filename); } - }, + } Err(RenderError::EmptyBuild) => (), Err(err) => { eprintln!("Image could not be rendered:"); -- cgit v1.2.3