use clap::Parser;
use ext_config::{Config, File, FileFormat};
use pool_sv2::config::PoolConfig;
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(author, version, about = "Pool CLI", long_about = None)]
pub struct Args {
#[arg(
short = 'c',
long = "config",
help = "Path to the TOML configuration file",
default_value = "pool-config.toml"
)]
pub config_path: PathBuf,
#[arg(
short = 'f',
long = "log-file",
help = "Path to the log file. If not set, logs will only be written to stdout."
)]
pub log_file: Option<PathBuf>,
}
#[cfg_attr(not(test), hotpath::measure)]
pub fn process_cli_args() -> PoolConfig {
let args = Args::parse();
let config_path = args.config_path.to_str().expect("Invalid config path");
let mut config: PoolConfig = Config::builder()
.add_source(File::new(config_path, FileFormat::Toml))
.build()
.and_then(|settings| settings.try_deserialize::<PoolConfig>())
.expect("Failed to load or deserialize config");
config.set_log_dir(args.log_file);
config
}