From 6584116e9da1a8389867584f079d868722753fca Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 10 Jun 2019 22:22:46 +0200 Subject: zotcli: Fetch group members by group id or group name. --- examples/zotcli.rs | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'examples/zotcli.rs') diff --git a/examples/zotcli.rs b/examples/zotcli.rs index ceb463b..2599531 100644 --- a/examples/zotcli.rs +++ b/examples/zotcli.rs @@ -24,6 +24,7 @@ use clap::{ }; use dotenv::dotenv; use std::env; +use std::str::FromStr; mod zot; @@ -56,6 +57,10 @@ fn main() { (@subcommand group => (about: "Fetch privacy groups") (@arg raw: --raw "Display raw json payload") + (@group selector => + (@arg ID: --id +takes_value "Fetch members of group ") + (@arg GNAME: --name +takes_value "Fetch members of group ") + ) ) (@subcommand xchan => (about: "Fetch xchan info") @@ -92,12 +97,41 @@ fn main() { zot::abook::fetch(&client, raw); }, ("group", Some(m)) => { - let res = client.group().fetch().unwrap(); - if m.is_present("raw") { - println!("{}", res); + if let Some(id) = m.value_of("ID") { + let res = client + .group_members() + .by_group_id(u64::from_str(id).unwrap()) + .fetch().unwrap(); + + if m.is_present("raw") { + println!("{}", res); + } + else { + zot::group::list_members(&res); + } + } + else if let Some(gname) = m.value_of("GNAME") { + let res = client + .group_members() + .by_group_name(gname) + .fetch().unwrap(); + + if m.is_present("raw") { + println!("{}", res); + } + else { + zot::group::list_members(&res); + } } else { - zot::group::list(&res); + let res = client.group().fetch().unwrap(); + + if m.is_present("raw") { + println!("{}", res); + } + else { + zot::group::list(&res); + } } }, ("xchan", Some(m)) => { -- cgit v1.2.3