Missing backends are no longer fatal

This commit is contained in:
Michael Bryan 2018-01-25 01:15:29 +08:00
parent 1fbad982d8
commit bda23f0183
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
2 changed files with 20 additions and 4 deletions

View File

@ -16,7 +16,7 @@ pub use self::html_handlebars::HtmlHandlebars;
mod html_handlebars;
use std::fs;
use std::io::Read;
use std::io::{self, Read};
use std::path::PathBuf;
use std::process::{Command, Stdio};
use serde_json;
@ -155,13 +155,22 @@ impl Renderer for CmdRenderer {
let _ = fs::create_dir_all(&ctx.destination);
let mut child = self.compose_command()?
let mut child = match self.compose_command()?
.stdin(Stdio::piped())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.current_dir(&ctx.destination)
.spawn()
.chain_err(|| "Unable to start the renderer")?;
.spawn() {
Ok(c) => c,
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {
warn!("The command wasn't found, is the \"{}\" backend installed?", self.name);
warn!("\tCommand: {}", self.cmd);
return Ok(());
}
Err(e) => {
return Err(e).chain_err(|| "Unable to start the backend")?;
}
};
{
let mut stdin = child.stdin.take().expect("Child has stdin");

View File

@ -24,6 +24,13 @@ fn failing_alternate_backend() {
md.build().unwrap_err();
}
#[test]
fn missing_backends_arent_fatal() {
let (md, _temp) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn");
assert!(md.build().is_ok());
}
#[test]
fn alternate_backend_with_arguments() {
let (md, _temp) = dummy_book_with_backend("arguments", "echo Hello World!");