1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-05-23 21:36:15 +02:00

started using clap to parse arguments

This commit is contained in:
Elisabeth Henry 2016-02-20 05:49:41 +01:00
parent b4e0acb3a5
commit 763c3671e8
2 changed files with 23 additions and 13 deletions

View File

@ -5,7 +5,7 @@ authors = ["Elisabeth Henry <liz.henry@ouvaton.org>"]
description = "Yet another converter from Markdown file to (HTML, LaTeX, Epub)"
repository = "https://github.com/lise-henry/crowbook"
readme = "README.md"
keywords = "markdown, book"
keywords = ["markdown", "book"]
license = "mit"
[lib]
@ -22,3 +22,4 @@ pulldown-cmark = "0.0.7"
mustache = "0.6"
chrono = "0.2"
uuid = "0.1"
clap = "2"

View File

@ -1,25 +1,34 @@
extern crate crowbook;
extern crate clap;
use crowbook::{Book};
use std::env;
use clap::{App,Arg};
fn main() {
let mut args = env::args();
args.next(); //discard program name
let mut app = App::new("crowbook")
.version(env!("CARGO_PKG_VERSION"))
.author("Élisabeth Henry")
.about("Render a markdown book in Epub, PDF or HTML")
.arg_from_usage("-v, --verbose 'Activate verbose mode'")
.arg_from_usage("-o, --output=[FILE] 'Specifies an output file'")
.arg(Arg::with_name("book")
.index(1)
.required(true)
.help("A file containing the book configuration"));
match args.next() {
None => println!("Needs the name of a book config file"),
Some(ref s) => {
match Book::new_from_file(s) {
Ok(book) => {
if let Err(err) = book.render_all() {
println!("{}", err);
}
}
Err(err) => {
let matches = app.get_matches();
if let Some(s) = matches.value_of("book") {
match Book::new_from_file(s) {
Ok(book) => {
if let Err(err) = book.render_all() {
println!("{}", err);
}
}
Err(err) => {
println!("{}", err);
}
}
}
}