checkmate-cli 0.4.1

Checkmate - API Testing Framework CLI
//! Checkmate - API Testing Framework CLI

use clap::{Parser, Subcommand};

mod clove;
mod config;
mod diff;
mod docs;
mod history;
mod hooks;
mod init;
mod prime;
mod project;
mod report;
mod runner;
mod spec;
mod test;

#[derive(Parser)]
#[command(name = "cm")]
#[command(about = "Checkmate - API Testing Framework")]
#[command(version)]
#[command(propagate_version = true)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Initialize Checkmate in current directory
    Init {
        /// Base URL for API tests (required in non-interactive mode)
        #[arg(short = 'L', long)]
        url: Option<String>,

        /// Stealth mode: add .checkmate/ to .git/info/exclude
        #[arg(long)]
        stealth: bool,
    },
    /// JSON query language operations
    Clove {
        #[command(subcommand)]
        command: clove::CloveCommands,
    },
    /// Run API tests
    Test {
        #[command(subcommand)]
        command: test::TestCommands,
    },
    /// Compare API responses across endpoints
    Diff {
        #[command(subcommand)]
        command: diff::DiffCommands,
    },
    /// Manage test specifications
    Spec {
        #[command(subcommand)]
        command: spec::SpecCommands,
    },
    /// Configuration management
    Config {
        #[command(subcommand)]
        command: config::ConfigCommands,
    },
    /// Report generation
    Report {
        #[command(subcommand)]
        command: report::ReportCommands,
    },
    /// Show documentation overview
    Docs,
    /// Show category-specific documentation
    Doc {
        /// Documentation category (assertions, requests, env, scopes, examples, cli)
        category: String,
    },
    /// Quick-start guide for AI agents
    Onboard,
    /// Show test run history
    History {
        /// Filter by git commit
        #[arg(long)]
        commit: Option<String>,
        /// Filter by spec file name
        #[arg(long)]
        spec: Option<String>,
        /// Maximum results to show
        #[arg(short = 'n', long, default_value = "10")]
        limit: usize,
    },
    /// Show details of a specific run
    Show {
        /// Run ID (e.g., cm-run-a3f)
        run_id: String,
    },
    /// Output project context for AI agents (used by hooks)
    Prime,
}

fn main() {
    rustls::crypto::ring::default_provider()
        .install_default()
        .expect("Failed to install rustls crypto provider");

    let cli = Cli::parse();

    let result = match cli.command {
        Commands::Init { url, stealth } => {
            init::run(init::InitOptions { url, stealth })
        }
        Commands::Clove { command } => clove::run(command),
        Commands::Test { command } => test::run(command),
        Commands::Diff { command } => diff::run(command),
        Commands::Spec { command } => spec::run(command),
        Commands::Config { command } => config::run(command),
        Commands::Report { command } => report::run(command),
        Commands::Docs => docs::run_docs(),
        Commands::Doc { category } => docs::run_doc(&category),
        Commands::Onboard => docs::run_onboard(),
        Commands::History { commit, spec, limit } => {
            history::run_history(commit.as_deref(), spec.as_deref(), limit)
        }
        Commands::Show { run_id } => history::run_show(&run_id),
        Commands::Prime => prime::run(),
    };

    if let Err(e) = result {
        eprintln!("Error: {}", e);
        std::process::exit(1);
    }
}