From 6ce87fdccbe092957ccc26e85e54ef4fd23f558b Mon Sep 17 00:00:00 2001 From: Elisabeth Henry Date: Tue, 20 Dec 2016 19:16:51 +0100 Subject: [PATCH] Read from stdin if book is set to '-' --- src/bin/real_main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bin/real_main.rs b/src/bin/real_main.rs index ef335ca..5743f03 100644 --- a/src/bin/real_main.rs +++ b/src/bin/real_main.rs @@ -19,11 +19,12 @@ extern crate clap; use helpers::*; -use crowbook::{Result, Book, BookOptions, InfoLevel, set_lang}; +use crowbook::{Result, Book, BookOptions, InfoLevel, set_lang, Error, Source}; use clap::ArgMatches; use std::process::exit; use std::fs::File; use std::io; +use std::io::Read; use std::env; @@ -149,9 +150,25 @@ pub fn try_main() -> Result<()> { .set_options(&get_book_options(&matches)); if matches.is_present("single") { - book.load_markdown_file(s)?; + if s != "-" { + book.load_markdown_file(s)?; + } else { + let mut buffer = String::new(); + io::stdin().read_to_string(&mut buffer) + .map_err(|_| Error::default(Source::empty(), + lformat!("Error reading from stdin")))?; + book.load_markdown_config(&buffer)?; + } } else { - book.load_file(s)?; + if s != "-" { + book.load_file(s)?; + } else { + let mut buffer = String::new(); + io::stdin().read_to_string(&mut buffer) + .map_err(|_| Error::default(Source::empty(), + lformat!("Error reading from stdin")))?; + book.load_config(&buffer)?; + } } set_book_options(&mut book, &matches);