use anyhow::Result; use clap::Parser; mod cli; mod config; mod docker; mod doctor; mod health; mod ssh; mod tmux; use crate::cli::{Cli, Commands}; use crate::config::{Cluster, Config, resolve_cluster_for_recipe, select_cluster_by_name}; use crate::ssh::fetch_host_key; #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); let cli = Cli::parse(); let raw_config = tokio::fs::read_to_string(&cli.config).await?; let config: Config = toml::from_str(&raw_config)?; let dry_run = cli.dry_run; match cli.command { Commands::Serve { recipe, cluster, keep, } => { docker::serve(&config, &recipe, &cluster, keep, dry_run).await?; } Commands::Logs { recipe: recipe_name, follow, } => { let (cluster, _recipe) = resolve_cluster_for_recipe(&config, &recipe_name).await?; docker::show_logs(&config, &cluster, &recipe_name, follow, dry_run).await?; } Commands::Stop { recipe: recipe_name, } => { let (cluster, _recipe) = resolve_cluster_for_recipe(&config, &recipe_name).await?; docker::stop_cluster(&config, &cluster, &recipe_name, dry_run).await?; } Commands::Health { cluster: cluster_name, fingerprint, } => { if fingerprint { let clusters_to_check: Vec = match &cluster_name { Some(name) => vec![select_cluster_by_name(&config, name)?], None => config.clusters.clone(), }; for cluster in &clusters_to_check { println!("\n=== Кластер: {} ===", cluster.name); for node in &cluster.nodes { match fetch_host_key(&config, node).await { Ok(fp) => { println!("{} ({}) -> host_key = \"{}\"", node.name, node.ssh_ip, fp) } Err(e) => println!("{} ({}) -> error: {}", node.name, node.ssh_ip, e), } } } } else { match cluster_name { Some(ref name) => { let cluster = select_cluster_by_name(&config, name)?; docker::health_check(&config, &cluster, dry_run).await?; } None => { for cluster in &config.clusters { docker::health_check(&config, cluster, dry_run).await?; } } } } } Commands::Doctor { recipe, cluster, repair, } => { doctor::doctor(&config, &recipe, &cluster, repair, dry_run).await?; } Commands::Tmux(tmux_cmd) => { crate::tmux::handle_tmux(&config, tmux_cmd, dry_run).await?; } } Ok(()) }