diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-03-29 13:08:09 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-03-29 13:08:09 +0200 |
commit | 8100cff32bf0c87dc19fba78f3faac8090f863da (patch) | |
tree | 7c6315dbb83162b8d91aae53b920c2e7f20a4268 /src/bin/zot/main.rs | |
parent | a4b9520f430ce188ba9165dcabd3320763ff2e16 (diff) | |
download | rust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.tar.gz rust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.tar.bz2 rust-zotapi-8100cff32bf0c87dc19fba78f3faac8090f863da.zip |
Another reqrite...
Third time must be where it sits I hope.
I felt the API was getting a bit too distracted by unnecessary
constructs and abstractions, so I'm trying to simplify it by making it
more straight forward.
The idea now is to have one main API class (ZotApi), and all the various
remote API's as public methods on this basic class. Iow, the ZotApi
class is mainly based on the existing `Client` class, which is then
being phased out.
And instead of having each API tied to the data type they return, I'm
just adding methods that will return the respective data types. This
should reduce coupling between the returned data, and the API calls
themselves.
Diffstat (limited to 'src/bin/zot/main.rs')
-rw-r--r-- | src/bin/zot/main.rs | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/bin/zot/main.rs b/src/bin/zot/main.rs index bf7b9b8..d09b5d4 100644 --- a/src/bin/zot/main.rs +++ b/src/bin/zot/main.rs @@ -18,45 +18,40 @@ use clap::{clap_app, crate_authors, crate_version}; use dotenv::dotenv; use std::env; -use std::str::FromStr; -use zotapi::ZotAPI; - -mod zot; #[tokio::main] -async fn main() { +async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> { dotenv().ok(); let site = env::var("HZ_SITE").expect("SITE variable expected"); - let user = env::var("HZ_USER").expect("USER variable expected"); + let channel = env::var("HZ_CHANNEL").expect("CHANNEL variable expected"); let password = env::var("HZ_PASSWORD").expect("PASSWORD variable expected"); let matches = clap_app!(app => (name: "zot") (version: crate_version!()) (author: crate_authors!()) - (about: "zotapi command line client") + (about: "zotapi command line client.") + (@arg raw: --raw "Display raw json payload.") + (@arg site: --site "Site to connect to.") + (@arg channel: --channel "The channel to connect as.") + (@arg password: --password "The password.") (@subcommand verify => (about: "Verify") - (@arg raw: --raw "Display raw json payload") ) (@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 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>") @@ -64,7 +59,6 @@ async fn main() { ) (@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") @@ -89,17 +83,14 @@ async fn main() { ) .get_matches(); - let client = zotapi::client(&site, &user, &password); + let z = zotapi::new(&site, &channel, &password); - match matches.subcommand() { - ("verify", Some(m)) => { - let r = zotapi::Channel::z(); - if m.is_present("raw") { - println!("{}", r.fetch_raw(&client).await.unwrap()); - } else { - println!("{:?}", r.fetch(&client).await); - } + Ok(match matches.subcommand() { + ("verify", Some(_)) => { + let channel = z.verify().await; + println!("{:?}", channel); } + /* ("channel", Some(m)) => { let raw = m.is_present("raw"); zot::channel_stream::fetch(&client, raw).await; @@ -178,8 +169,10 @@ async fn main() { ("post", Some(m)) => { zot::item::post(&client, m).await; } + */ _ => { + println!("Not a known command, or it's not implemented yet."); println!("{}", matches.usage()); } - } + }) } |