aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-06-10 22:22:46 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-06-10 22:22:46 +0200
commit6584116e9da1a8389867584f079d868722753fca (patch)
tree3ba548112d02ebd7c1655ce915ed69b812aaabe4 /examples
parent8158bee4cbb5cc599c38788f0aa12a489e5261c1 (diff)
downloadrust-zotapi-6584116e9da1a8389867584f079d868722753fca.tar.gz
rust-zotapi-6584116e9da1a8389867584f079d868722753fca.tar.bz2
rust-zotapi-6584116e9da1a8389867584f079d868722753fca.zip
zotcli: Fetch group members by group id or group name.
Diffstat (limited to 'examples')
-rw-r--r--examples/zot/group.rs19
-rw-r--r--examples/zotcli.rs42
2 files changed, 57 insertions, 4 deletions
diff --git a/examples/zot/group.rs b/examples/zot/group.rs
index 6bb3839..e02fb13 100644
--- a/examples/zot/group.rs
+++ b/examples/zot/group.rs
@@ -50,3 +50,22 @@ pub fn list(data: &str) {
eprintln!("Invalid data");
}
}
+
+
+pub fn list_members(data: &str) {
+ if let Ok(Value::Array(members)) = from_str(&data) {
+
+ println!("Id | Name | Address");
+ println!("----+-------------------------------+------------------------");
+
+ for member in members {
+ println!("{:>3} | {:29} | {}",
+ member["id"].as_u64().unwrap(),
+ member["xchan_name"].as_str().unwrap(),
+ member["xchan_addr"].as_str().unwrap());
+ }
+ }
+ else {
+ eprintln!("Invalid data");
+ }
+}
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 <ID>")
+ (@arg GNAME: --name +takes_value "Fetch members of group <GNAME>")
+ )
)
(@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)) => {