atrium_cli/
commands.rs

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 (Create an authentication session).
9    Login(LoginArgs),
10    /// Get a view of an actor's home timeline.
11    GetTimeline,
12    /// Get a view of an actor's feed.
13    GetAuthorFeed(ActorArgs),
14    /// Get a list of likes for a given post.
15    GetLikes(UriArgs),
16    /// Get a list of reposts for a given post.
17    GetRepostedBy(UriArgs),
18    /// Get a list of feeds created by an actor.
19    GetActorFeeds(ActorArgs),
20    /// Get a view of a hydrated feed.
21    GetFeed(UriArgs),
22    /// Get a view of a specified list,
23    GetListFeed(UriArgs),
24    /// Get a list of who an actor follows.
25    GetFollows(ActorArgs),
26    /// Get a list of an actor's followers.
27    GetFollowers(ActorArgs),
28    /// Get a list of the list created by an actor.
29    GetLists(ActorArgs),
30    /// Get detailed info of a specified list.
31    GetList(UriArgs),
32    /// Get detailed profile view of an actor.
33    GetProfile(ActorArgs),
34    /// Get preferences of an actor.
35    GetPreferences,
36    /// Get a list of notifications.
37    ListNotifications,
38    /// Get a list of chat conversations.
39    ListConvos,
40    /// Send a message to a chat conversation.
41    SendConvoMessage(SendConvoMessageArgs),
42    /// Create a new post.
43    CreatePost(CreatePostArgs),
44    /// Delete a post.
45    DeletePost(UriArgs),
46}
47
48#[derive(Parser, Debug)]
49pub struct LoginArgs {
50    /// Handle or other identifier supported by the server for the authenticating user.
51    #[arg(short, long)]
52    pub(crate) identifier: String,
53    /// Password
54    #[arg(short, long)]
55    pub(crate) password: String,
56}
57
58#[derive(Parser, Debug)]
59pub struct ActorArgs {
60    /// Actor's handle or did
61    #[arg(short, long, value_parser)]
62    pub(crate) actor: Option<AtIdentifier>,
63}
64
65#[derive(Parser, Debug)]
66pub struct UriArgs {
67    /// Record's URI
68    #[arg(short, long, value_parser)]
69    pub(crate) uri: AtUri,
70}
71
72#[derive(Parser, Debug)]
73pub struct SendConvoMessageArgs {
74    /// Actor's handle or did
75    #[arg(short, long, value_parser)]
76    pub(crate) actor: AtIdentifier,
77    /// Message text
78    #[arg(short, long)]
79    pub(crate) text: String,
80}
81
82#[derive(Parser, Debug)]
83pub struct CreatePostArgs {
84    /// Post text
85    #[arg(short, long)]
86    pub(crate) text: String,
87    /// Images to embed
88    #[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}