#[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};
#[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 {
New(NewArgs),
Run(RunArgs),
Watch(WatchArgs),
Add(AddArgs),
Bench(BenchArgs),
Doctor(DoctorArgs),
Observability(ObservabilityArgs),
#[command(subcommand)]
Generate(GenerateArgs),
#[command(subcommand)]
Migrate(MigrateArgs),
Docs {
#[arg(short, long, default_value = "8080")]
port: u16,
},
Client(ClientArgs),
#[command(subcommand)]
Deploy(DeployArgs),
#[cfg(feature = "replay")]
#[command(subcommand)]
Replay(ReplayArgs),
}
impl Cli {
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,
}
}
}