Skip to main content

htb_cli/cli/
seasons.rs

1use clap::Subcommand;
2
3use crate::api::HtbClient;
4use crate::output::{self, OutputFormat};
5
6#[derive(Subcommand)]
7pub enum SeasonCommand {
8    /// List all seasons
9    List,
10    /// Show your rank in the current season
11    Rank,
12}
13
14pub async fn handle(
15    client: &HtbClient,
16    cmd: SeasonCommand,
17    format: OutputFormat,
18) -> anyhow::Result<()> {
19    match cmd {
20        SeasonCommand::List => {
21            let seasons = client.seasons().list().await?;
22            output::print_list(&seasons, format);
23        }
24
25        SeasonCommand::Rank => {
26            let user = client.user().current().await?;
27            let ranks = client.seasons().user_ranks(user.id).await?;
28
29            if ranks.is_empty() {
30                output::print_message("No season data found.");
31            } else {
32                output::print_list(&ranks, format);
33            }
34        }
35    }
36    Ok(())
37}