use crate::{
OnceCommand,
command::bands::{ListBandPlans, ShowBandPlan, ShowItuAllocations},
error::CliError,
};
use clap::{Args, Subcommand};
use rfham_core::countries::CountryCode;
use rfham_itu::allocations::FrequencyAllocation;
use std::process::ExitCode;
use tracing::instrument;
#[derive(Debug, Subcommand)]
pub enum BandPlanCommands {
List,
Itu,
Show(CmdShowBandPlan),
}
#[derive(Debug, Args)]
#[command(arg_required_else_help = true)]
pub struct CmdShowBandPlan {
#[arg(short = 'b', long, requires = "country")]
band: Vec<FrequencyAllocation>,
#[arg(env = "RFHAM_COUNTRY")]
country: CountryCode,
}
impl OnceCommand for BandPlanCommands {
type Output = ExitCode;
type Error = CliError;
fn execute(self) -> Result<Self::Output, Self::Error> {
match self {
Self::List => ListBandPlans.execute(),
Self::Itu => ShowItuAllocations.execute(),
Self::Show(cmd_show_band_plan) => cmd_show_band_plan.execute(),
}
}
}
impl OnceCommand for CmdShowBandPlan {
type Output = ExitCode;
type Error = CliError;
#[instrument(name = "bandplan_show")]
fn execute(self) -> Result<Self::Output, Self::Error> {
ShowBandPlan::new(self.country, self.band).execute()
}
}