1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-09-30 04:51:21 +02:00

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
This commit is contained in:
Elisabeth Henry 2016-03-01 17:43:40 +01:00
parent 61f4dabff5
commit 7be4af4264
2 changed files with 11 additions and 3 deletions

@ -86,6 +86,7 @@ pub fn create_matches<'a>() -> ArgMatches<'a> {
.setting(AppSettings::UnifiedHelpMessage) .setting(AppSettings::UnifiedHelpMessage)
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.about("Render a markdown book in Epub, PDF or HTML.") .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("-v, --verbose 'Print warnings in parsing/rendering'")
.arg_from_usage("-d, --debug 'Print additional information") .arg_from_usage("-d, --debug 'Print additional information")
.arg_from_usage("--create [FILES]... 'Creates a new book with existing markdown files.'") .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")) .requires("to"))
.arg(Arg::from_usage("-t, --to [FORMAT] 'Generate specific format'") .arg(Arg::from_usage("-t, --to [FORMAT] 'Generate specific format'")
.possible_values(&["epub", "pdf", "html", "tex", "odt"])) .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)) .min_values(2))
.arg(Arg::from_usage("-l --list-options 'Lists all possible options")) .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_from_usage("--print-template [TEMPLATE] 'Displays the default value of a template.'")
.arg(Arg::with_name("BOOK") .arg(Arg::with_name("BOOK")
.index(1) .index(1)

@ -137,7 +137,14 @@ fn main() {
} else { } else {
InfoLevel::Info 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)), Err(err) => print_error(&format!("{}", err)),
Ok(mut book) => { Ok(mut book) => {
set_book_options(&mut book, &matches); set_book_options(&mut book, &matches);