Skip to content

Commit

Permalink
Merge pull request #91 from sugyan/feature/update-cli
Browse files Browse the repository at this point in the history
Update cli
  • Loading branch information
sugyan authored Dec 6, 2023
2 parents e730ca9 + b050e88 commit 1d10428
Show file tree
Hide file tree
Showing 8 changed files with 435 additions and 573 deletions.
9 changes: 5 additions & 4 deletions atrium-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ edition = "2021"
authors = ["sugyan <[email protected]>"]

[dependencies]
atrium-xrpc = { path = "../atrium-xrpc" }
atrium-api = "0.3"
async-trait = "0.1.74"
atrium-api = "0.14"
atrium-xrpc-client = "0.2"
chrono = "0.4.24"
clap = { version = "4.2.4", features = ["derive"] }
clap = { version = "4.4.8", features = ["derive"] }
dirs = "5.0.1"
serde = "1.0.160"
serde_json = "1.0"
tokio = { version = "1", features = ["full"] }
toml = "0.7.3"
98 changes: 12 additions & 86 deletions atrium-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,22 @@
Usage: atrium-cli [OPTIONS] <COMMAND>
Commands:
create-record Create a new record (post, repost, like, block)
create-app-password Create a new app password
delete-record Delete record
get-session Get current session info
get-profile Get a profile of an actor (default: current session)
get-record Get record
get-timeline Get timeline
get-follows Get following of an actor (default: current session)
get-followers Get followers of an actor (default: current session)
get-author-feed Get a feed of an author (default: current session)
get-post-thread Get a post thread
get-likes Get likes of a record
get-blocks Get a list of blocking actors
list-notifications List notifications
list-app-passwords List app passwords
revoke-app-password Revoke an app password
help Print this message or the help of the given subcommand(s)
login Login (Create an authentication session)
get-timeline Get a view of the actor's home timeline
get-author-feed Get a view of an actor's feed
get-likes Get the list of likes
get-reposted-by Get a list of reposts
get-follows Get a list of who the actor follows
get-followers Get a list of an actor's followers
get-profile Get detailed profile view of an actor
list-notifications Get a list of notifications
create-post Create a new post
delete-post Delete a post
help Print this message or the help of the given subcommand(s)
Options:
-p, --pds-host <PDS_HOST> [default: https://bsky.social]
-c, --config <CONFIG> Path to config file [default: config.toml]
-d, --debug Debug print
-h, --help Print help
-V, --version Print version
```

## sub commands

```
Create a new record (post, repost, like, block)
Usage: atrium-cli create-record <COMMAND>
Commands:
post Create a post
repost Create a repost
like Like a record
block Block an actor
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
```

```
Create a post
Usage: atrium-cli create-record post [OPTIONS] <TEXT>
Arguments:
<TEXT> Text of the post
Options:
-r, --reply <REPLY> URI of the post to reply to
-i, --image <IMAGE> image files
-h, --help Print help
```

```
Create a repost
Usage: atrium-cli create-record repost <URI>
Arguments:
<URI> URI of the post to repost
Options:
-h, --help Print help
```

```
Like a record
Usage: atrium-cli create-record like <URI>
Arguments:
<URI> URI of an record to like
Options:
-h, --help Print help
```

```
Block an actor
Usage: atrium-cli create-record block <DID>
Arguments:
<DID> DID of an actor to block
Options:
-h, --help Print help
```
26 changes: 26 additions & 0 deletions atrium-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use atrium_cli::runner::Runner;
use clap::Parser;
use std::fmt::Debug;

#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Args {
#[arg(short, long, default_value = "https://bsky.social")]
pds_host: String,
/// Debug print
#[arg(short, long)]
debug: bool,
#[command(subcommand)]
// command: Command,
command: atrium_cli::commands::Command,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
Runner::new(args.pds_host, args.debug)
.await?
.run(args.command)
.await;
Ok(())
}
89 changes: 89 additions & 0 deletions atrium-cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use clap::Parser;
use std::str::FromStr;

#[derive(Parser, Debug)]
pub enum Command {
/// Login (Create an authentication session).
Login(LoginArgs),
/// Get a view of the actor's home timeline.
GetTimeline,
/// Get a view of an actor's feed.
GetAuthorFeed(ActorArgs),
/// Get the list of likes.
GetLikes(UriArgs),
/// Get a list of reposts.
GetRepostedBy(UriArgs),
/// Get a list of who the actor follows.
GetFollows(ActorArgs),
/// Get a list of an actor's followers.
GetFollowers(ActorArgs),
/// Get detailed profile view of an actor.
GetProfile(ActorArgs),
/// Get a list of notifications.
ListNotifications,
/// Create a new post.
CreatePost(CreatePostArgs),
/// Delete a post.
DeletePost(UriArgs),
}

#[derive(Parser, Debug)]
pub struct LoginArgs {
/// Handle or other identifier supported by the server for the authenticating user.
#[arg(short, long)]
pub(crate) identifier: String,
/// Password
#[arg(short, long)]
pub(crate) password: String,
}

#[derive(Parser, Debug)]
pub struct ActorArgs {
/// Actor's handle or did
#[arg(short, long)]
pub(crate) actor: Option<String>,
}

#[derive(Parser, Debug)]
pub struct UriArgs {
/// Record's URI
#[arg(short, long, value_parser)]
pub(crate) uri: AtUri,
}

#[derive(Parser, Debug)]
pub struct CreatePostArgs {
/// Post text
#[arg(short, long, value_parser)]
pub(crate) text: String,
}

#[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)
}
}
3 changes: 3 additions & 0 deletions atrium-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod commands;
pub mod runner;
pub mod store;
Loading

0 comments on commit 1d10428

Please sign in to comment.