-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from sugyan/feature/update-cli
Update cli
- Loading branch information
Showing
8 changed files
with
435 additions
and
573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod commands; | ||
pub mod runner; | ||
pub mod store; |
Oops, something went wrong.