churn-v2/crates/churn/src/cli.rs
kjuulh ee323e99e8
All checks were successful
continuous-integration/drone/push Build is passing
feat: add discovery
Signed-off-by: kjuulh <contact@kjuulh.io>
2024-11-24 17:12:15 +01:00

70 lines
1.7 KiB
Rust

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<Commands>,
}
#[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,
},
}