use clap::{Parser, Subcommand};
use rust_config_tree::{ConfigCommand, handle_config_command, load_config};
use rust_supervisor::config::configurable::SupervisorConfig;
use std::path::PathBuf;
const DEFAULT_CONFIG_PATH: &str = "examples/config/supervisor.yaml";
#[derive(Debug, Parser)]
#[command(name = "rust-tokio-supervisor")]
struct Cli {
#[arg(long)]
config: Option<PathBuf>,
#[command(subcommand)]
command: Option<Command>,
}
#[derive(Debug, Subcommand)]
enum Command {
Run,
#[command(flatten)]
Config(ConfigCommand),
}
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if std::env::args_os().len() == 1 {
let program = std::env::args_os()
.next()
.unwrap_or_else(|| "rust-tokio-supervisor".into());
let _ = Cli::parse_from([program, "--help".into()]);
return Ok(());
}
let cli = Cli::parse();
let config_path = cli
.config
.unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG_PATH));
match cli.command.unwrap_or(Command::Run) {
Command::Run => {
let config = load_config::<SupervisorConfig>(&config_path)?;
println!("config path: {}", config_path.display());
println!("strategy: {:?}", config.supervisor.strategy);
println!("children: {}", config.children.len());
}
Command::Config(command) => {
handle_config_command::<Cli, SupervisorConfig>(command, &config_path)?;
}
}
Ok(())
}