skytool 0.1.0-pre.2

an experimental API client for BlueSky / ATProto
Documentation
#![allow(unused)]

use std::str::FromStr;

use clap::Parser;
use miette::IntoDiagnostic;
use tap::{Pipe, Tap};

mod default;
mod input;
mod integrations;
pub(crate) mod macros;
mod ops;
mod options;
mod output;
pub(crate) mod parse;
mod patch;
mod query;
mod source;
mod xrpc;

pub mod transcode;

pub async fn main() -> miette::Result<()> {
  Command::parse().run().await.into_diagnostic()?;
  Ok(())
}

pub(crate) trait Output: erased_serde::Serialize {}
erased_serde::serialize_trait_object!(Output);

impl crate::Output for () {}
impl crate::Output for String {}
impl<T> crate::Output for Vec<T> where T: crate::Output + serde::Serialize {}
impl crate::Output for std::collections::BTreeMap<String, Box<dyn crate::Output>> {}
impl crate::Output for schemars::schema::RootSchema {}
impl crate::Output for bsky_sdk::agent::config::Config {}
impl crate::Output for json_patch::Patch {}
// impl crate::Output for serde_json::Value {}
// impl crate::Output for serde_yml::Value {}

#[derive(Debug, Clone, clap::Parser)]
#[allow(clippy::large_enum_variant)]
#[remain::sorted]
#[command(about = "a commandline tool for bluesky/atproto and related operations")]
pub(crate) enum Command {
  Ops(ops::Command),
  Xrpc(xrpc::Command),
}

crate::macros::impl_subcommand!(
  (Command) => (run()) => {
    ops,
    xrpc
  }
);

#[derive(Debug, thiserror::Error, miette::Diagnostic)]
#[error(transparent)]
pub(crate) enum Error {
  Ops(#[from] ops::Error),
  Keyring(#[from] keyring::Error),
  Json(#[from] serde_json::Error),
  Yaml(#[from] serde_yml::Error),
  Io(#[from] std::io::Error),
  #[error("missing authority")]
  MissingAuthority,
  #[error("missing password")]
  MissingPassword,
  Xrpc(#[from] xrpc::Error),
}