1use atrium_api::types::string::AtIdentifier;
2use clap::Parser;
3use std::path::PathBuf;
4use std::str::FromStr;
5
6#[derive(Parser, Debug)]
7pub enum Command {
8 Login(LoginArgs),
10 GetTimeline,
12 GetAuthorFeed(ActorArgs),
14 GetLikes(UriArgs),
16 GetRepostedBy(UriArgs),
18 GetActorFeeds(ActorArgs),
20 GetFeed(UriArgs),
22 GetListFeed(UriArgs),
24 GetFollows(ActorArgs),
26 GetFollowers(ActorArgs),
28 GetLists(ActorArgs),
30 GetList(UriArgs),
32 GetProfile(ActorArgs),
34 GetPreferences,
36 ListNotifications,
38 ListConvos,
40 SendConvoMessage(SendConvoMessageArgs),
42 CreatePost(CreatePostArgs),
44 DeletePost(UriArgs),
46}
47
48#[derive(Parser, Debug)]
49pub struct LoginArgs {
50 #[arg(short, long)]
52 pub(crate) identifier: String,
53 #[arg(short, long)]
55 pub(crate) password: String,
56}
57
58#[derive(Parser, Debug)]
59pub struct ActorArgs {
60 #[arg(short, long, value_parser)]
62 pub(crate) actor: Option<AtIdentifier>,
63}
64
65#[derive(Parser, Debug)]
66pub struct UriArgs {
67 #[arg(short, long, value_parser)]
69 pub(crate) uri: AtUri,
70}
71
72#[derive(Parser, Debug)]
73pub struct SendConvoMessageArgs {
74 #[arg(short, long, value_parser)]
76 pub(crate) actor: AtIdentifier,
77 #[arg(short, long)]
79 pub(crate) text: String,
80}
81
82#[derive(Parser, Debug)]
83pub struct CreatePostArgs {
84 #[arg(short, long)]
86 pub(crate) text: String,
87 #[arg(short, long)]
89 pub(crate) images: Vec<PathBuf>,
90}
91
92#[derive(Debug, Clone)]
93pub(crate) struct AtUri {
94 pub(crate) did: String,
95 pub(crate) collection: String,
96 pub(crate) rkey: String,
97}
98
99impl FromStr for AtUri {
100 type Err = String;
101
102 fn from_str(s: &str) -> Result<Self, Self::Err> {
103 let parts = s
104 .strip_prefix("at://did:plc:")
105 .ok_or(r#"record uri must start with "at://did:plc:""#)?
106 .splitn(3, '/')
107 .collect::<Vec<_>>();
108 Ok(Self {
109 did: format!("did:plc:{}", parts[0]),
110 collection: parts[1].to_string(),
111 rkey: parts[2].to_string(),
112 })
113 }
114}
115
116impl std::fmt::Display for AtUri {
117 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
118 write!(f, "at://{}/{}/{}", self.did, self.collection, self.rkey)
119 }
120}