aimo-cli 0.4.0

AiMo Network client CLI
use clap::Parser;
use colored::Colorize;

use crate::{
    args::{CliArgs, CommandArgs},
    keygen::generate_secret_key,
    topup::top_up_escrow,
};

mod args;
mod config;
mod keygen;
mod proxy;
mod topup;

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();

    let args = CliArgs::parse();

    match args.command {
        // aimo keygen
        CommandArgs::Keygen {
            tag,
            valid_for,
            scopes,
            usage_limit,
            id,
        } => {
            if let Err(err) = generate_secret_key(&tag, valid_for, scopes, usage_limit, id)
                .map(|sk| println!("{sk}"))
            {
                println!("Error: {err}");
                std::process::exit(1);
            }
        }

        // aimo proxy
        CommandArgs::Proxy { config, id } => {
            println!(
                "{}",
                "**DEPRECATED**: The `proxy` command is deprecated and will be removed in future versions. Please use the `aimo-proxy` command instead.".yellow()
            );
            println!(
                "{}",
                "For more information, visit: https://docs.aimo.network/provider-guide".blue()
            );
            if let Err(err) = proxy::serve_websocket_with_config(config, id).await {
                println!("Error: {err}");
                std::process::exit(1);
            }
        }

        // aimo topup
        CommandArgs::Topup {
            amount,
            id,
            rpc_url,
            router_url,
            devnet_tokens,
            token,
        } => {
            if let Err(err) =
                top_up_escrow(amount, id, rpc_url, router_url, devnet_tokens, token).await
            {
                println!("Error: {err}");
                std::process::exit(1);
            }
        }
    }
}