diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-06-09 20:01:10 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-06-09 20:01:10 +0200 |
commit | 8f352330d2189c0f6065812c7f3dbdab2e6d3c9e (patch) | |
tree | db148bbec5b70fda339ec6a8fbddc2f9b941e66e /examples | |
parent | eed9d6ee002e1ad034b3db7057b5a0f8338a736a (diff) | |
download | rust-zotapi-8f352330d2189c0f6065812c7f3dbdab2e6d3c9e.tar.gz rust-zotapi-8f352330d2189c0f6065812c7f3dbdab2e6d3c9e.tar.bz2 rust-zotapi-8f352330d2189c0f6065812c7f3dbdab2e6d3c9e.zip |
Use clap_app macro to define args at compile time.
For some reason the clap_app macro does not accept subcommands
with hyphens, so the subcommands `channel-strean` and `network-stream`
has been changed to `channel` and `network` respectively.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/zotcli.rs | 94 |
1 files changed, 37 insertions, 57 deletions
diff --git a/examples/zotcli.rs b/examples/zotcli.rs index 672e3ef..565d3ff 100644 --- a/examples/zotcli.rs +++ b/examples/zotcli.rs @@ -15,19 +15,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -extern crate zotapi; -extern crate dotenv; -extern crate clap; -extern crate serde_json; - use clap::{ - Arg, - app_from_crate, + clap_app, crate_name, crate_version, crate_authors, crate_description, - SubCommand }; use dotenv::dotenv; use std::env; @@ -40,62 +33,49 @@ fn main() { let user = env::var("HZ_USER").expect("USER variable expected"); let password = env::var("HZ_PASSWORD").expect("PASSWORD variable expected"); - let matches = app_from_crate!() - .subcommand( - SubCommand::with_name("channel-stream") - .about("Fetch the channel stream") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("network-stream") - .about("Fetch the network stream") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("abook") - .about("Fetch address book/contact info") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload"))) - .subcommand( - SubCommand::with_name("abconfig") - .about("Fetch abconfig")) - .subcommand( - SubCommand::with_name("xchan") - .about("Fetch xchan info") - .arg(Arg::with_name("raw") - .long("raw") - .help("Display raw json payload")) - .arg(Arg::with_name("addr") - .long("addr") - .help("ID is given as a webbie address (default)")) - .arg(Arg::with_name("hash") - .long("hash") - .help("ID is given as a xchan hash")) - .arg(Arg::with_name("guid") - .long("guid") - .help("ID is given as a GUID")) - .arg(Arg::with_name("ID") - .help("id (email, hash or GUID) of xchan to fetch") - .required(true))) - .subcommand( - SubCommand::with_name("post") - .about("Post a new message") - .arg(Arg::with_name("BODY") - .help("body of message") - .required(true))) - .get_matches(); + let matches = clap_app!(app => + (name: crate_name!()) + (version: crate_version!()) + (author: crate_authors!()) + (about: crate_description!()) + (@subcommand channel => + (about: "Fetch the channel stream") + (@arg raw: --raw "Display raw json payload") + ) + (@subcommand network => + (about: "Fetch the network stream") + (@arg raw: --raw "Display raw json payload") + ) + (@subcommand abook => + (about: "Fetch address book/contact info") + (@arg raw: --raw "Display raw json payload") + ) + (@subcommand abconfig => + (about: "Fetch abconfig") + ) + (@subcommand xchan => + (about: "Fetch xchan info") + (@arg raw: --raw "Display raw json payload") + (@arg addr: --addr "ID is given as webbie (default)") + (@arg hash: --hash "ID is given as xchan hash") + (@arg guid: --guid "ID is given as a GUID") + (@arg ID: +required "id (webbie, hash or GUID) of xchan to fetch") + ) + (@subcommand post => + (about: "Post a new message") + (@arg BODY: +required "Body of the message") + ) + ) + .get_matches(); let client = zotapi::client(&site, &user, &password); match matches.subcommand() { - ("channel-stream", Some(m)) => { + ("channel", Some(m)) => { let raw = m.is_present("raw"); zot::channel_stream::fetch(&client, raw); }, - ("network-stream", Some(m)) => { + ("network", Some(m)) => { let raw = m.is_present("raw"); zot::network_stream::fetch(&client, raw); }, |