mirror of
https://github.com/lise-henry/crowbook
synced 2024-11-18 00:13:55 +01:00
started using clap to parse arguments
This commit is contained in:
parent
b4e0acb3a5
commit
763c3671e8
@ -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"
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user