Skip to content

Commit

Permalink
Add limit option
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan committed Apr 18, 2024
1 parent 7a1a070 commit ad15728
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions atrium-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Commands:
Options:
-p, --pds-host <PDS_HOST> [default: https://bsky.social]
-l, --limit <LIMIT> Limit the number of items returned [default: 10]
-d, --debug Debug print
-h, --help Print help
-V, --version Print version
Expand Down
18 changes: 14 additions & 4 deletions atrium-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ use std::fmt::Debug;
struct Args {
#[arg(short, long, default_value = "https://bsky.social")]
pds_host: String,
/// Limit the number of items returned
#[arg(
short,
long,
default_value = "10",
value_parser = clap::value_parser!(u8).range(1..=100)
)]
limit: u8,
/// Debug print
#[arg(short, long)]
debug: bool,
Expand All @@ -18,8 +26,10 @@ struct Args {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
Ok(Runner::new(args.pds_host, args.debug)
.await?
.run(args.command)
.await?)
Ok(
Runner::new(args.pds_host, args.limit.try_into()?, args.debug)
.await?
.run(args.command)
.await?,
)
}
7 changes: 5 additions & 2 deletions atrium-cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{Context, Result};
use atrium_api::agent::{store::SessionStore, AtpAgent};
use atrium_api::records::{KnownRecord, Record};
use atrium_api::types::string::{AtIdentifier, Datetime, Handle};
use atrium_api::types::LimitedNonZeroU8;
use atrium_xrpc_client::reqwest::ReqwestClient;
use serde::Serialize;
use std::ffi::OsStr;
Expand All @@ -13,13 +14,14 @@ use tokio::io::AsyncReadExt;

pub struct Runner {
agent: AtpAgent<SimpleJsonFileSessionStore, ReqwestClient>,
limit: LimitedNonZeroU8<100>,
debug: bool,
session_path: PathBuf,
handle: Option<Handle>,
}

impl Runner {
pub async fn new(pds_host: String, debug: bool) -> Result<Self> {
pub async fn new(pds_host: String, limit: LimitedNonZeroU8<100>, debug: bool) -> Result<Self> {
let config_dir = dirs::config_dir()
.with_context(|| format!("No config dir: {:?}", dirs::config_dir()))?;
let dir = config_dir.join("atrium-cli");
Expand All @@ -34,13 +36,14 @@ impl Runner {
}
Ok(Self {
agent,
limit,
debug,
session_path,
handle,
})
}
pub async fn run(&self, command: Command) -> Result<()> {
let limit = 10.try_into().expect("within limit");
let limit = self.limit;
match command {
Command::Login(args) => {
self.agent.login(args.identifier, args.password).await?;
Expand Down

0 comments on commit ad15728

Please sign in to comment.