use clap::{Parser, Subcommand};

mod api;
mod commands;
mod config;

/// The `sprouts` CLI — the primary client for the Sprouts platform.
#[derive(Parser)]
#[command(name = "sprouts", version, about = "Build, deploy, and operate Sprouts automations", long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    /// Sign in via the browser and save a session.
    Login(commands::login::Args),
    /// Sign out and clear the saved session.
    Logout,
    /// Show the saved session.
    Whoami,
    /// Scaffold a new sprout in the current directory.
    Init(commands::init::Args),
    /// Deploy a sprout to the Sprouts platform.
    Deploy(commands::deploy::Args),
    /// Manually run a handler.
    Run(commands::run::Args),
    /// View logs for a deployed sprout.
    Logs(commands::logs::Args),
    /// Roll a sprout back to a previous deployment.
    Rollback(commands::rollback::Args),
}

fn main() -> anyhow::Result<()> {
    match Cli::parse().command {
        Command::Login(args) => commands::login::run(args),
        Command::Logout => commands::logout::run(),
        Command::Whoami => commands::whoami::run(),
        Command::Init(args) => commands::init::run(args),
        Command::Deploy(args) => commands::deploy::run(args),
        Command::Run(args) => commands::run::run(args),
        Command::Logs(args) => commands::logs::run(args),
        Command::Rollback(args) => commands::rollback::run(args),
    }
}
