aimo-cli 0.2.0

AiMo Network client CLI
use clap::Parser;

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 } => {
            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);
            }
        }
    }
}