kvs/src/bin/kvs.rs

57 lines
1.4 KiB
Rust

#[macro_use]
extern crate clap;
use std::process::{abort, exit};
fn parse_args() -> Result<(), &'static str> {
let matches = clap_app!(myapp =>
(version: env!("CARGO_PKG_VERSION"))
(author: env!("CARGO_PKG_AUTHORS"))
(about: env!("CARGO_PKG_DESCRIPTION"))
(@arg version: -V "Print the version")
(@subcommand get =>
(about: "Get the string value of a given string key")
(@arg key: +required "The key to lookup")
)
(@subcommand set =>
(about: "Set the value of a string key to a string")
(@arg key: +required "The key to set")
(@arg value: +required "The value to set")
)
(@subcommand rm =>
(about: "Remove a given key")
(@arg key: +required "The key to remove")
)
).get_matches();
match matches.subcommand_name() {
Some("get") => {
Err("unimplemented")
},
Some("set") => {
Err("unimplemented")
},
Some("rm") => {
Err("unimplemented")
},
_ => {
if matches.is_present("version") {
println!(env!("CARGO_PKG_VERSION"));
return Ok(());
}
Err("")
}
}
}
fn main() {
match parse_args() {
Ok(_) => exit(0),
Err(err) => {
eprintln!("{}", err);
abort()
}
}
}