use clap::{Parser, Subcommand};
use anyhow::Result;
mod init;
mod fund;
mod test;
mod utils;
#[derive(Parser)]
#[command(name = "xforth")]
#[command(version = "0.1.0")]
#[command(about = "CLI tool for bootstrapping x402 Solana projects in under 90 seconds", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(long, global = true)]
rpc: Option<String>,
#[arg(long, global = true)]
local: bool,
#[arg(long, global = true)]
no_color: bool,
#[arg(long, global = true)]
json: bool,
}
#[derive(Subcommand)]
enum Commands {
Init {
#[arg(default_value = "my-x402-agent")]
name: String,
},
Fund,
Test,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
if cli.no_color {
colored::control::set_override(false);
}
let rpc_url = if cli.local {
"http://127.0.0.1:8899".to_string()
} else {
cli.rpc.unwrap_or_else(|| "https://api.devnet.solana.com".to_string())
};
match cli.command {
Commands::Init { name } => {
init::run(&name, &rpc_url, cli.json).await?;
}
Commands::Fund => {
fund::run(&rpc_url, cli.json).await?;
}
Commands::Test => {
test::run(&rpc_url, cli.json).await?;
}
}
Ok(())
}