use std::net::SocketAddr; use clap::{Parser, Subcommand}; use crate::{agent, server}; pub async fn execute() -> anyhow::Result<()> { let cli = Command::parse(); match cli.command.expect("to have a subcommand") { Commands::Serve { host, grpc_host, config, } => { tracing::info!("Starting service"); server::execute(host, grpc_host, config).await?; } Commands::Agent { commands } => match commands { AgentCommands::Start {} => { tracing::info!("starting agent"); agent::execute().await?; tracing::info!("shut down agent"); } AgentCommands::Setup { force, discovery } => { agent::setup_config(discovery, force).await?; tracing::info!("wrote default agent config"); } }, } Ok(()) } #[derive(Parser)] #[command(author, version, about, long_about = None, subcommand_required = true)] struct Command { #[command(subcommand)] command: Option, } #[derive(Subcommand)] enum Commands { Serve { #[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")] host: SocketAddr, #[arg(env = "SERVICE_GRPC_HOST", long, default_value = "127.0.0.1:7900")] grpc_host: SocketAddr, #[clap(flatten)] config: server::config::ServerConfig, }, Agent { #[command(subcommand)] commands: AgentCommands, }, } #[derive(Subcommand)] enum AgentCommands { Start {}, Setup { #[arg(long, default_value = "false")] force: bool, #[arg(env = "DISCOVERY_HOST", long = "discovery")] discovery: String, }, }