From 7be4af42648cc4d18f5eff4b7f99abaa24c5cb52 Mon Sep 17 00:00:00 2001 From: Elisabeth Henry Date: Tue, 1 Mar 2016 17:43:40 +0100 Subject: [PATCH] Add option --single to the binary This option allows Crowbook to parse a single MarkDown file, defaulting to hide the chapters' headings. This should allow to get ride of `.book` file for short stories. Resolves: #2, #3 --- src/bin/helpers.rs | 5 +++-- src/bin/main.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bin/helpers.rs b/src/bin/helpers.rs index 5ce0325..ea3f017 100644 --- a/src/bin/helpers.rs +++ b/src/bin/helpers.rs @@ -86,6 +86,7 @@ pub fn create_matches<'a>() -> ArgMatches<'a> { .setting(AppSettings::UnifiedHelpMessage) .version(env!("CARGO_PKG_VERSION")) .about("Render a markdown book in Epub, PDF or HTML.") + .arg_from_usage("-s, --single 'Create a book from a single MarkDown file'") .arg_from_usage("-v, --verbose 'Print warnings in parsing/rendering'") .arg_from_usage("-d, --debug 'Print additional information") .arg_from_usage("--create [FILES]... 'Creates a new book with existing markdown files.'") @@ -93,10 +94,10 @@ pub fn create_matches<'a>() -> ArgMatches<'a> { .requires("to")) .arg(Arg::from_usage("-t, --to [FORMAT] 'Generate specific format'") .possible_values(&["epub", "pdf", "html", "tex", "odt"])) - .arg(Arg::from_usage("-s, --set [KEY_VALUES] 'Sets a list of book options'") + .arg(Arg::from_usage("--set [KEY_VALUES] 'Sets a list of book options'") .min_values(2)) .arg(Arg::from_usage("-l --list-options 'Lists all possible options")) - .arg_from_usage("--list-options-md 'List all options, formatted in Markdown") + .arg_from_usage("--list-options-md 'List all options, formatted in Markdown.'") .arg_from_usage("--print-template [TEMPLATE] 'Displays the default value of a template.'") .arg(Arg::with_name("BOOK") .index(1) diff --git a/src/bin/main.rs b/src/bin/main.rs index accf8a5..1659f2b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -137,7 +137,14 @@ fn main() { } else { InfoLevel::Info }; - match Book::new_from_file(s, verbosity) { + + let book_res = if matches.is_present("single") { + Book::new_from_markdown_file(s, verbosity) + } else { + Book::new_from_file(s, verbosity) + }; + + match book_res { Err(err) => print_error(&format!("{}", err)), Ok(mut book) => { set_book_options(&mut book, &matches);