From 8f352330d2189c0f6065812c7f3dbdab2e6d3c9e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 Jun 2019 20:01:10 +0200 Subject: 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. --- Cargo.toml | 2 +- examples/zotcli.rs | 94 +++++++++++++++++++++--------------------------------- 2 files changed, 38 insertions(+), 58 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a6d634..c8115e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ serde = "1.0" serde_urlencoded = "0.5.1" [dev-dependencies] -clap = "2.32.0" +clap = "2.33.0" dotenv = "0.13" mockito = "0.14" serde_json = "1.0" 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 . */ -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); }, -- cgit v1.2.3