use clap::{Parser, Subcommand};
use colored::Colorize;
mod api;
mod commands;
mod exec_client;
use commands::{batch, bootstrap, deploy, exec, list, mcp, provider, spawn, status, system, topup};
#[derive(Parser)]
#[command(name = "paygress-cli")]
#[command(author = "Dhananjay Purohit")]
#[command(version = env!("CARGO_PKG_VERSION"))]
#[command(about = "CLI tool for Paygress - spawn compute with Lightning + Nostr", long_about = None)]
struct Cli {
#[arg(short, long, global = true)]
verbose: bool,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
List(list::ListArgs),
Spawn(spawn::SpawnArgs),
Deploy(deploy::DeployArgs),
Topup(topup::TopupArgs),
Status(status::StatusArgs),
Batch(batch::BatchArgs),
Mcp(mcp::McpArgs),
Exec(exec::ExecArgs),
Provider(provider::ProviderArgs),
Bootstrap(bootstrap::BootstrapArgs),
System(system::SystemArgs),
}
fn print_banner() {
println!("{}", "PAYGRESS CLI".blue().bold());
println!("{}", "Pay-per-Use Compute with Lightning + Nostr".blue());
println!();
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.with_writer(std::io::stderr)
.init();
let cli = Cli::parse();
if cli.verbose {
print_banner();
}
let result = match cli.command {
Commands::List(args) => list::execute(args, cli.verbose).await,
Commands::Spawn(args) => spawn::execute(args, cli.verbose).await,
Commands::Deploy(args) => deploy::execute(args, cli.verbose).await,
Commands::Topup(args) => topup::execute(args, cli.verbose).await,
Commands::Status(args) => status::execute(args, cli.verbose).await,
Commands::Batch(args) => batch::execute(args, cli.verbose).await,
Commands::Mcp(args) => mcp::execute(args, cli.verbose).await,
Commands::Exec(args) => exec::execute(args, cli.verbose).await,
Commands::Provider(args) => provider::execute(args, cli.verbose).await,
Commands::Bootstrap(args) => bootstrap::execute(args, cli.verbose).await,
Commands::System(args) => system::execute(args, cli.verbose).await,
};
if let Err(e) = result {
eprintln!("{} {}", "Error:".red().bold(), e);
std::process::exit(1);
}
}