aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)) => {