cargo-rustapi 0.1.450

The official CLI tool for the RustAPI framework. Scaffold new projects, run development servers, and manage database migrations.
//! CLI argument parsing

#[cfg(feature = "replay")]
use crate::commands::ReplayArgs;
use crate::commands::{
    self, AddArgs, BenchArgs, ClientArgs, DeployArgs, DoctorArgs, GenerateArgs, MigrateArgs,
    NewArgs, ObservabilityArgs, RunArgs, WatchArgs,
};
use clap::{Parser, Subcommand};

/// The official CLI tool for the RustAPI framework. Scaffold new projects, run development servers, and manage database migrations.
#[derive(Parser, Debug)]
#[command(name = "cargo-rustapi")]
#[command(bin_name = "cargo rustapi")]
#[command(author, version, about)]
#[command(
    long_about = "The official CLI tool for the RustAPI framework.\n\nUsage:\n  cargo rustapi <COMMAND>\n  cargo-rustapi <COMMAND>\n\nBoth forms are equivalent and can be used interchangeably."
)]
pub struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Create a new RustAPI project
    New(NewArgs),

    /// Run the development server
    Run(RunArgs),

    /// Watch for changes and auto-reload (dedicated)
    Watch(WatchArgs),

    /// Add a feature or dependency
    Add(AddArgs),

    /// Run the benchmark workflow
    Bench(BenchArgs),

    /// Check environment health
    Doctor(DoctorArgs),

    /// Surface observability docs and baseline workflow assets
    Observability(ObservabilityArgs),

    /// Generate code from templates
    #[command(subcommand)]
    Generate(GenerateArgs),

    /// Database migration commands
    #[command(subcommand)]
    Migrate(MigrateArgs),

    /// Open API documentation in browser
    Docs {
        /// Port to check for running server
        #[arg(short, long, default_value = "8080")]
        port: u16,
    },

    /// Generate API client from OpenAPI spec
    Client(ClientArgs),

    /// Deploy to various platforms
    #[command(subcommand)]
    Deploy(DeployArgs),

    /// Replay debugging commands (time-travel debugging)
    #[cfg(feature = "replay")]
    #[command(subcommand)]
    Replay(ReplayArgs),
}

impl Cli {
    /// Execute the CLI command
    pub async fn execute(self) -> anyhow::Result<()> {
        match self.command {
            Commands::New(args) => commands::new_project(args).await,
            Commands::Run(args) => commands::run_dev(args).await,
            Commands::Watch(args) => commands::watch(args).await,
            Commands::Add(args) => commands::add(args).await,
            Commands::Bench(args) => commands::bench(args).await,
            Commands::Doctor(args) => commands::doctor(args).await,
            Commands::Observability(args) => commands::observability(args).await,
            Commands::Generate(args) => commands::generate(args).await,
            Commands::Migrate(args) => commands::migrate(args).await,
            Commands::Docs { port } => commands::open_docs(port).await,
            Commands::Client(args) => commands::client(args).await,
            Commands::Deploy(args) => commands::deploy(args).await,
            #[cfg(feature = "replay")]
            Commands::Replay(args) => commands::replay(args).await,
        }
    }
}