tranc-cli 0.1.1

Tranc CLI — trade indicator queries from the command line.
//! `tranc` CLI binary entry point.
//!
//! Commands:
//!   tranc auth login|whoami|logout|key create|key list|key revoke
//!   tranc <indicator> <symbol> [--tf <tf>] [--period <n>] [--pretty]
//!   tranc batch <file.yaml>
//!   tranc usage
//!   tranc symbols list [--asset crypto|fx] [--q <query>]
//!   tranc bug-report [--title <summary>] [--command <cmd>] [--log <file>]
//!
//! Default output is raw JSON for LLM piping.
//! Use `--pretty` for human-readable output.
//!
//! Resolves issue #21, #22, and #72.

mod client;
mod cmd;
mod config;
mod keyring_store;
mod output;

use anyhow::Result;
use clap::{Parser, Subcommand};

use cmd::auth::AuthCmd;
use cmd::batch::BatchCmd;
use cmd::bug_report::BugReportCmd;
use cmd::indicator::IndicatorCmd;
use cmd::symbols::SymbolsCmd;
use cmd::usage::UsageCmd;

/// Tranc — LLM-optimized trading indicators.
#[derive(Debug, Parser)]
#[command(name = "tranc", version, about, long_about = None)]
struct Cli {
    /// API base URL (overrides TRANC_API_URL env var and default).
    #[arg(long, global = true, env = "TRANC_API_URL")]
    api_url: Option<String>,

    /// Pretty-print the JSON response for human reading.
    #[arg(long, global = true)]
    pretty: bool,

    #[command(subcommand)]
    command: Commands,
}

#[derive(Debug, Subcommand)]
enum Commands {
    /// Authentication: login, whoami, logout, manage API keys.
    Auth(AuthCmd),

    /// List available symbols.
    Symbols(SymbolsCmd),

    /// Single indicator query (rsi, ema, macd, bb, atr, …).
    ///
    /// Examples:
    ///   tranc indicator rsi BTC-USD --tf 5m --period 14
    ///   tranc indicator macd ETH-USD --tf 1h
    ///   tranc indicator bb BTC-USD --tf 15m --pretty
    Indicator(IndicatorCmd),

    /// Batch indicator queries from a YAML file.
    Batch(BatchCmd),

    /// Show current-period usage.
    Usage(UsageCmd),

    /// Open a pre-filled GitHub bug report in the browser.
    BugReport(BugReportCmd),
}

#[tokio::main]
async fn main() -> Result<()> {
    let cli = Cli::parse();

    let api_url = cli
        .api_url
        .unwrap_or_else(|| "https://api.tranc.ai".to_string());

    let pretty = cli.pretty;

    match cli.command {
        Commands::Auth(cmd) => cmd.run(&api_url, pretty).await,
        Commands::Symbols(cmd) => cmd.run(&api_url, pretty).await,
        Commands::Indicator(cmd) => cmd.run(&api_url, pretty).await,
        Commands::Batch(cmd) => cmd.run(&api_url, pretty).await,
        Commands::Usage(cmd) => cmd.run(&api_url, pretty).await,
        Commands::BugReport(cmd) => cmd.run(),
    }
}