use std::path::PathBuf;
use clap::{Parser, Subcommand};
use crate::{
cli_run::{compile::Compile, config_check::ConfigCheck, CliRun},
config::ConfigUrl,
};
#[derive(Debug, Subcommand)]
pub enum ConfigCommand {
Check {
#[arg(
short,
long,
value_name = "CONFIG",
default_value = "https://raw.githubusercontent.com/ragibkl/adblock-dns-server/master/data/configuration.yaml"
)]
config_url: ConfigUrl,
},
}
#[derive(Debug, Subcommand)]
pub enum Command {
#[command(subcommand)]
Config(ConfigCommand),
Compile {
#[arg(
short,
long,
value_name = "CONFIG",
default_value = "https://raw.githubusercontent.com/ragibkl/adblock-dns-server/master/data/configuration.yaml"
)]
config_url: ConfigUrl,
#[arg(short, long, value_name = "OUTPUT", default_value = "./blacklist.zone")]
output: PathBuf,
#[arg(short, long, value_name = "FORMAT", default_value = "zone")]
format: String,
},
}
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
impl Cli {
pub fn from_args() -> Self {
Self::parse()
}
pub fn into_cli_run(self) -> Box<dyn CliRun> {
match &self.command {
Command::Config(config_cmd) => match config_cmd {
ConfigCommand::Check { config_url } => Box::new(ConfigCheck::new(config_url)),
},
Command::Compile {
config_url,
output,
format,
} => Box::new(Compile::new(config_url, output, format)),
}
}
}