From 1faed7ed865b9e2ff81201b90b6377d149fd5a54 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 24 Nov 2017 22:15:39 +0000 Subject: [PATCH] Use fixed list of output types --- src/config/mod.rs | 12 +++++++++--- src/main.rs | 1 - src/output/mod.rs | 4 ++-- src/output/pdf/mod.rs | 4 ++-- test-files/mdp.yml | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 475297b..3f225d9 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -9,10 +9,16 @@ use std::io::Read; pub mod consts; pub mod csl; +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Clone)] +pub enum OutputType { + PDF, + HTML +} + #[derive(Debug, Serialize, Deserialize, Default, Clone)] pub struct Config { input: Vec, - output: HashMap, + output: HashMap, pub title: String, #[serde(default = "default_verbosity")] @@ -30,11 +36,11 @@ pub struct References { impl Config { - pub fn absolute_output(&self, output_type: String) -> PathBuf { + pub fn absolute_output(&self, output_type: OutputType) -> PathBuf { return resolve_path(self.output.get(&output_type).unwrap()); } - pub fn has_output(&self, output_type: String) -> bool { + pub fn has_output(&self, output_type: OutputType) -> bool { return self.output.contains_key(&output_type); } diff --git a/src/main.rs b/src/main.rs index f498e4e..59dc99f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,6 @@ fn get_config(args: ArgMatches) -> Config { fn main() { let args = args::get_matches(); let subcommand = args.subcommand_name().expect("subcommand error"); - match subcommand { "build" => { let config = get_config(args.clone()); diff --git a/src/output/mod.rs b/src/output/mod.rs index f845b15..1a17c02 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -1,9 +1,9 @@ -use config::Config; +use config::{Config, OutputType}; pub mod pdf; pub fn output(config: Config, output: String) -> Result<(), String> { - if config.has_output("pdf".into()) { + if config.has_output(OutputType::PDF) { try!(pdf::output(config, output)); } return Ok(()); diff --git a/src/output/pdf/mod.rs b/src/output/pdf/mod.rs index 4352c77..0bcf1fe 100644 --- a/src/output/pdf/mod.rs +++ b/src/output/pdf/mod.rs @@ -1,4 +1,4 @@ -use config::Config; +use config::{Config, OutputType}; use utils::result_override; use std::error::Error; @@ -25,7 +25,7 @@ fn create_builder<'a>(config: Config, builder: &'a mut PdfBuilder) -> &'a mut Pd } pub fn output(config: Config, html: String) -> Result<(), String> { - let output_location = &config.absolute_output("pdf".into()); + let output_location = &config.absolute_output(OutputType::PDF); let mut pdf_app = try!(result_override(PdfApplication::new(), "Failed to create PDF Application".into())); let mut base_builder = pdf_app.builder(); diff --git a/test-files/mdp.yml b/test-files/mdp.yml index 6141439..08af668 100644 --- a/test-files/mdp.yml +++ b/test-files/mdp.yml @@ -6,7 +6,7 @@ input: - ipsum.md - end.md output: - pdf: output.pdf + PDF: output.pdf title: test title references: bibliography: bib.yaml