use atrium_api::types::string::AtIdentifier;
use clap::Parser;
use std::path::PathBuf;
use std::str::FromStr;
#[derive(Parser, Debug)]
pub enum Command {
Login(LoginArgs),
GetTimeline,
GetAuthorFeed(ActorArgs),
GetLikes(UriArgs),
GetRepostedBy(UriArgs),
GetActorFeeds(ActorArgs),
GetFeed(UriArgs),
GetListFeed(UriArgs),
GetFollows(ActorArgs),
GetFollowers(ActorArgs),
GetLists(ActorArgs),
GetList(UriArgs),
GetProfile(ActorArgs),
GetPreferences,
ListNotifications,
ListConvos,
SendConvoMessage(SendConvoMessageArgs),
CreatePost(CreatePostArgs),
DeletePost(UriArgs),
}
#[derive(Parser, Debug)]
pub struct LoginArgs {
#[arg(short, long)]
pub(crate) identifier: String,
#[arg(short, long)]
pub(crate) password: String,
}
#[derive(Parser, Debug)]
pub struct ActorArgs {
#[arg(short, long, value_parser)]
pub(crate) actor: Option<AtIdentifier>,
}
#[derive(Parser, Debug)]
pub struct UriArgs {
#[arg(short, long, value_parser)]
pub(crate) uri: AtUri,
}
#[derive(Parser, Debug)]
pub struct SendConvoMessageArgs {
#[arg(short, long, value_parser)]
pub(crate) actor: AtIdentifier,
#[arg(short, long)]
pub(crate) text: String,
}
#[derive(Parser, Debug)]
pub struct CreatePostArgs {
#[arg(short, long)]
pub(crate) text: String,
#[arg(short, long)]
pub(crate) images: Vec<PathBuf>,
}
#[derive(Debug, Clone)]
pub(crate) struct AtUri {
pub(crate) did: String,
pub(crate) collection: String,
pub(crate) rkey: String,
}
impl FromStr for AtUri {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let parts = s
.strip_prefix("at://did:plc:")
.ok_or(r#"record uri must start with "at://did:plc:""#)?
.splitn(3, '/')
.collect::<Vec<_>>();
Ok(Self {
did: format!("did:plc:{}", parts[0]),
collection: parts[1].to_string(),
rkey: parts[2].to_string(),
})
}
}
impl std::fmt::Display for AtUri {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "at://{}/{}/{}", self.did, self.collection, self.rkey)
}
}