Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/commands/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ pub enum CommentsCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,
},

/// Get a comment by ID
Expand All @@ -69,9 +73,13 @@ pub enum CommentsCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,
},
}

Expand Down Expand Up @@ -105,14 +113,21 @@ pub async fn execute(
offset,
order,
ascending,
descending,
} => {
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = CommentsRequest::builder()
.parent_entity_type(ParentEntityType::from(entity_type))
.parent_entity_id(entity_id)
.limit(limit)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.build();

let comments = client.comments(&request).await?;
Expand Down Expand Up @@ -143,14 +158,21 @@ pub async fn execute(
offset,
order,
ascending,
descending,
} => {
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let addr = parse_address(&address)?;
let request = CommentsByUserAddressRequest::builder()
.user_address(addr)
.limit(limit)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.build();

let comments = client.comments_by_user_address(&request).await?;
Expand Down
16 changes: 13 additions & 3 deletions src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ pub enum EventsCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,

/// Filter by tag slug (e.g. "politics", "crypto")
#[arg(long)]
tag: Option<String>,
Expand Down Expand Up @@ -71,15 +75,21 @@ pub async fn execute(client: &gamma::Client, args: EventsArgs, output: OutputFor
offset,
order,
ascending,
descending,
tag,
} => {
let resolved_closed = closed.or_else(|| active.map(|a| !a));
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = EventsRequest::builder()
.limit(limit)
.maybe_closed(resolved_closed)
.maybe_offset(offset)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.maybe_tag_slug(tag)
.order(order.into_iter().collect::<Vec<_>>())
.build();
Expand Down
72 changes: 69 additions & 3 deletions src/commands/markets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ pub enum MarketsCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,
},

/// Get a single market by ID or slug
Expand Down Expand Up @@ -87,15 +91,21 @@ pub async fn execute(
offset,
order,
ascending,
descending,
} => {
let resolved_closed = closed.or_else(|| active.map(|a| !a));
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = MarketsRequest::builder()
.limit(limit)
.maybe_closed(resolved_closed)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.build();

let markets = client.markets(&request).await?;
Expand Down Expand Up @@ -156,3 +166,59 @@ pub async fn execute(

Ok(())
}

#[cfg(test)]
mod tests {
use polymarket_client_sdk::gamma::types::request::MarketsRequest;
use polymarket_client_sdk::ToQueryParams;

fn resolve_sort(ascending: bool, descending: bool) -> Option<bool> {
match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
}
}

#[test]
fn no_flag_omits_ascending_param() {
let sort = resolve_sort(false, false);
let request = MarketsRequest::builder()
.limit(25)
.maybe_ascending(sort)
.build();
let qs = request.query_params(None);
assert!(
!qs.contains("ascending"),
"expected ascending param to be omitted, got: {qs}"
);
}

#[test]
fn ascending_flag_sends_true() {
let sort = resolve_sort(true, false);
let request = MarketsRequest::builder()
.limit(25)
.maybe_ascending(sort)
.build();
let qs = request.query_params(None);
assert!(
qs.contains("ascending=true"),
"expected ascending=true, got: {qs}"
);
}

#[test]
fn descending_flag_sends_false() {
let sort = resolve_sort(false, true);
let request = MarketsRequest::builder()
.limit(25)
.maybe_ascending(sort)
.build();
let qs = request.query_params(None);
assert!(
qs.contains("ascending=false"),
"expected ascending=false, got: {qs}"
);
}
}
17 changes: 14 additions & 3 deletions src/commands/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ pub enum SeriesCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,

/// Filter by closed status
#[arg(long)]
closed: Option<bool>,
Expand All @@ -53,13 +57,20 @@ pub async fn execute(client: &gamma::Client, args: SeriesArgs, output: OutputFor
offset,
order,
ascending,
descending,
closed,
} => {
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = SeriesListRequest::builder()
.limit(limit)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.maybe_closed(closed)
.build();

Expand Down
17 changes: 14 additions & 3 deletions src/commands/sports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ pub enum SportsCommand {
#[arg(long)]
order: Option<String>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,

/// Filter by league
#[arg(long)]
league: Option<String>,
Expand Down Expand Up @@ -68,13 +72,20 @@ pub async fn execute(client: &gamma::Client, args: SportsArgs, output: OutputFor
offset,
order,
ascending,
descending,
league,
} => {
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = TeamsRequest::builder()
.limit(limit)
.maybe_offset(offset)
.maybe_order(order)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.league(league.into_iter().collect::<Vec<_>>())
.build();

Expand Down
17 changes: 14 additions & 3 deletions src/commands/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ pub enum TagsCommand {
#[arg(long)]
offset: Option<i32>,

/// Sort ascending instead of descending
#[arg(long)]
/// Sort ascending
#[arg(long, conflicts_with = "descending")]
ascending: bool,

/// Sort descending
#[arg(long, conflicts_with = "ascending")]
descending: bool,
},

/// Get a single tag by ID or slug
Expand Down Expand Up @@ -68,11 +72,18 @@ pub async fn execute(client: &gamma::Client, args: TagsArgs, output: OutputForma
limit,
offset,
ascending,
descending,
} => {
let sort_ascending = match (ascending, descending) {
(true, _) => Some(true),
(_, true) => Some(false),
_ => None,
};

let request = TagsRequest::builder()
.limit(limit)
.maybe_offset(offset)
.maybe_ascending(if ascending { Some(true) } else { None })
.maybe_ascending(sort_ascending)
.build();

let tags = client.tags(&request).await?;
Expand Down