tranc-cli 0.1.1

Tranc CLI — trade indicator queries from the command line.
//! `tranc usage` subcommand — show current-period consumption.

use anyhow::Result;
use clap::Parser;

use crate::client::{build_client, get_json};
use crate::config::canonical_base_url;
use crate::output::print_json;

/// `tranc usage` — show API usage for the current billing period.
#[derive(Debug, Parser)]
pub struct UsageCmd {}

impl UsageCmd {
    pub async fn run(self, api_url: &str, pretty: bool) -> Result<()> {
        let base = canonical_base_url(api_url);
        let (client, token) = build_client()?;
        let url = format!("{base}/v1/usage");
        let rb = client.get(&url).bearer_auth(&token);
        let json = get_json(rb).await?;
        print_json(&json, pretty)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::Parser;

    #[test]
    fn parse_usage_no_args() {
        UsageCmd::try_parse_from(["usage"]).unwrap();
    }
}