command line argument parsing

master
Tom Alexander 5 years ago
parent 5d9c90c9b0
commit ab75624667

@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
docopt = "1.1.0"
serde = "1.0.91"

@ -1,3 +1,37 @@
use docopt::Docopt;
use serde::Deserialize;
static USAGE: &'static str = "
foil
Usage:
foil set [--db=<db>]
foil get [--db=<db>]
foil list [--db=<db>]
foil generate <spec>
foil (-h | --help)
Options:
--db=<db> The path to the sqlite database [default: db.sqlite3].
-h --help Show this screen.
--version Show version.
";
#[derive(Debug, Deserialize)]
struct Args {
cmd_set: bool,
cmd_get: bool,
cmd_list: bool,
cmd_generate: bool,
flag_db: Option<String>,
arg_spec: Option<String>,
}
fn main() {
println!("Hello, world!");
let args: Args = Docopt::new(USAGE)
.and_then(|dopt| dopt.deserialize())
.unwrap_or_else(|e| e.exit());
println!("{:?}", args);
}

Loading…
Cancel
Save