use crate::{
OnceCommand,
command::config::{InitializeConfig, ShowCurrentConfig},
error::CliError,
};
use clap::{Args, Subcommand};
use rfham_config::paths::ConfigPath;
use rfham_core::{callsign::CallSign, country::CountryCode};
use rfham_geo::grid::maidenhead::MaidenheadLocator;
use rfham_itu::regions::Region;
use std::{path::PathBuf, process::ExitCode};
#[derive(Debug, Subcommand)]
pub enum ConfigCommands {
Show(CmdShowConfig),
Init(CmdInitConfig),
}
#[derive(Debug, Args)]
pub struct CmdShowConfig {
#[arg(long)]
config_file: Option<PathBuf>,
path: Option<ConfigPath>,
}
#[derive(Debug, Args)]
pub struct CmdInitConfig {
#[arg(long)]
config_file: Option<PathBuf>,
#[arg(short = 'w', long, default_value_t = false)]
overwrite: bool,
#[arg(short = 'n', long)]
operator_name: Option<String>,
#[arg(short = 'l', long)]
locator: Option<MaidenheadLocator>,
#[arg(short = 'r', long)]
pub itu_region: Option<Region>,
#[arg(short = 'c', long)]
pub country: Option<CountryCode>,
#[arg(short = 'a', long)]
pub mailing_address: Option<String>,
callsign: CallSign,
}
impl OnceCommand for ConfigCommands {
type Output = ExitCode;
type Error = CliError;
fn execute(self) -> Result<Self::Output, Self::Error> {
match self {
Self::Show(cmd) => cmd.execute(),
Self::Init(cmd) => cmd.execute(),
}
}
}
impl OnceCommand for CmdShowConfig {
type Output = ExitCode;
type Error = CliError;
fn execute(self) -> Result<Self::Output, Self::Error> {
ShowCurrentConfig::new(self.config_file, self.path).execute()
}
}
impl OnceCommand for CmdInitConfig {
type Output = ExitCode;
type Error = CliError;
fn execute(self) -> Result<Self::Output, Self::Error> {
InitializeConfig::new(
self.config_file,
self.overwrite,
self.callsign,
self.operator_name,
self.locator,
self.itu_region,
self.country,
self.mailing_address,
)
.execute()
}
}