diff options
author | Michael Bryan <michaelfbryan@gmail.com> | 2018-09-19 22:38:16 +0800 |
---|---|---|
committer | Jan-Erik Rediger <janerik@fnordig.de> | 2019-07-09 11:11:09 +0200 |
commit | b1f6eb2fb52f4395e725b12380ab3525556f2784 (patch) | |
tree | 5a0c83730fb57d648b96b55bec70df7b15f196c2 /src | |
parent | 46e8410f4170b2e1b0f19116c4465e9cb6cd83b2 (diff) |
Changed the version check from a panic!() to an error message
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/mdbook-mermaid.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/bin/mdbook-mermaid.rs b/src/bin/mdbook-mermaid.rs index 8762c79..e672a03 100644 --- a/src/bin/mdbook-mermaid.rs +++ b/src/bin/mdbook-mermaid.rs @@ -3,10 +3,9 @@ extern crate mdbook; extern crate mdbook_mermaid; extern crate serde_json; -use clap::{App, ArgMatches}; +use clap::{App, Arg, ArgMatches, SubCommand}; use mdbook::errors::Error; -use mdbook::preprocessor::CmdPreprocessor; -use mdbook::MDBook; +use mdbook::preprocess::{CmdPreprocessor, Preprocessor}; use mdbook_mermaid::Mermaid; use std::io; @@ -24,14 +23,13 @@ pub fn make_app() -> App<'static, 'static> { fn main() { let matches = make_app().get_matches(); - let result = match matches.subcommand_matches("supports") { - Some(sub_args) => handle_supports(sub_args), - None => handle_preprocessing(), - }; - - if let Err(e) = result { - eprintln!("{}", e); - process::exit(1); + if let Some(sub_args) = matches.subcommand_matches("supports") { + handle_supports(sub_args); + } else { + if let Err(e) = handle_preprocessing() { + eprintln!("{}", e); + process::exit(1); + } } } @@ -40,16 +38,23 @@ fn handle_preprocessing() -> Result<(), Error> { .expect("Couldn't parse the input"); if ctx.mdbook_version != mdbook::MDBOOK_VERSION { - return Err(Error::from("The version check failed!")); + // We should probably use the `semver` crate to check compatibility + // here... + eprintln!( + "Warning: The mdbook-mermaid plugin was built against version \ + {} of mdbook, but we're being called from version {}", + mdbook::MDBOOK_VERSION, + ctx.mdbook_version + ); } - let processed_book = Mermaid.run(&ctx, &book)?; + let processed_book = Mermaid.run(&ctx, book)?; serde_json::to_writer(io::stdout(), &processed_book)?; Ok(()) } -fn handle_supports(sub_args: &ArgMatches) { +fn handle_supports(sub_args: &ArgMatches) -> ! { let renderer = sub_args.value_of("renderer").expect("Required argument"); let supported = Mermaid.supports_renderer(&renderer); |