aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-cli/src/bin
diff options
context:
space:
mode:
authorbryan newbold <bnewbold@robocracy.org>2023-02-20 02:03:17 -0800
committerbryan newbold <bnewbold@robocracy.org>2023-02-20 02:03:17 -0800
commitae9b55206d174a89a84453c7499ca87b3ce6df0f (patch)
treea9689caeae98d016123054569bf4a6ea8efd4052 /adenosine-cli/src/bin
parentb1b437ce1f83ebfb8808964846c964cac5e907c2 (diff)
downloadadenosine-ae9b55206d174a89a84453c7499ca87b3ce6df0f.tar.gz
adenosine-ae9b55206d174a89a84453c7499ca87b3ce6df0f.zip
cli: initial support for pretty-printing feeds
Diffstat (limited to 'adenosine-cli/src/bin')
-rw-r--r--adenosine-cli/src/bin/adenosine.rs40
1 files changed, 36 insertions, 4 deletions
diff --git a/adenosine-cli/src/bin/adenosine.rs b/adenosine-cli/src/bin/adenosine.rs
index 169e5d7..aae6a87 100644
--- a/adenosine-cli/src/bin/adenosine.rs
+++ b/adenosine-cli/src/bin/adenosine.rs
@@ -1,3 +1,4 @@
+use adenosine::app_bsky;
use adenosine::auth::parse_did_from_jwt;
use adenosine::created_at_now;
use adenosine::identifiers::*;
@@ -312,7 +313,7 @@ fn require_auth_did(opt: &Opt, xrpc_client: &mut XrpcClient) -> Result<Did> {
xrpc_client.auth_login(handle, passwd)?;
} else {
return Err(anyhow!(
- "command requires auth, but have neither token orhandle/password"
+ "command requires auth, but have neither token or handle/password"
));
}
xrpc_client.auth_did()
@@ -586,16 +587,47 @@ fn run(opt: Opt) -> Result<()> {
.map(|v| v.to_string())
.unwrap_or(require_auth_did(&opt, &mut xrpc_client)?.to_string());
params.insert("author".to_string(), name);
- xrpc_client.get(
+ let resp = xrpc_client.get(
&Nsid::from_str("app.bsky.feed.getAuthorFeed")?,
Some(params),
- )?
+ )?;
+ let resp = resp.ok_or(anyhow!("expected resp from getAuthorFeed"))?;
+ if atty::is(atty::Stream::Stdout) {
+ for val in resp["feed"]
+ .as_array()
+ .ok_or(anyhow!("expected feed from getAuthorFeed"))?
+ .iter()
+ {
+ let val: serde_json::Value = val.clone();
+ let fi: app_bsky::FeedPostView = serde_json::from_value(val)?;
+ pretty::pp_post_view(&fi.post)?;
+ }
+ None
+ } else {
+ Some(resp)
+ }
}
Command::Bsky {
cmd: BskyCommand::Timeline,
} => {
require_auth_did(&opt, &mut xrpc_client)?;
- xrpc_client.get(&Nsid::from_str("app.bsky.feed.getTimeline")?, None)?
+ let resp = xrpc_client.get(&Nsid::from_str("app.bsky.feed.getTimeline")?, None)?;
+ let resp = resp.ok_or(anyhow!("expected resp from getTimeline"))?;
+ if atty::is(atty::Stream::Stdout) {
+ for val in resp["feed"]
+ .as_array()
+ .ok_or(anyhow!("expected feed from getTimeline"))?
+ .iter()
+ {
+ let val: serde_json::Value = val.clone();
+ //print_result_json(Some(val.clone()))?;
+ let fi: app_bsky::FeedPostView = serde_json::from_value(val)?;
+ pretty::pp_post_view(&fi.post)?;
+ }
+ None
+ } else {
+ Some(resp)
+ }
}
Command::Bsky {
cmd: BskyCommand::Notifications,