pdns-cli 0.0.3

Rust client library and CLI for the PowerDNS Authoritative Server API
Documentation
//! the cli module of the pdns-cli binary crate

mod server;
use server::ServerCommands;

use clap::{Parser, Subcommand};

// pub(crate) keeps the item public for this crate only
// this is needed to work around the unreachable pub linting errors -
// since the porject contains both binary and library crates this lint often fires for modules that are only supposed to be used in the binaries

/// CLI tool for `PowerDNS` API
///
/// CLI tool for interfacing with `PowerDNS` Authoritative DNS Server API
/// Currently, supports the server API
#[derive(Parser, Debug)]
#[command(version, about, long_about)]
pub(crate) struct Cli {
    /// the base url pdns api requests will be made against
    #[arg(long, visible_alias = "url", env = "PDNS_WEBSERVER_URL")]
    pub(crate) webserver_url: String,

    /// the api key used to authenticate to pdns webserver
    ///
    /// this is supplied via the `X-API-Key` header in the request
    #[arg(long, env = "PDNS_API_KEY")]
    pub(crate) api_key: String,

    /// top level command to execute
    #[command(subcommand)]
    pub(crate) command: Commands,
}

/// Top level commands supported by the CLI
#[derive(Debug, Subcommand)]
#[command(about, long_about)]
pub(crate) enum Commands {
    /// server commands variant
    Servers {
        /// server command to execute
        #[command(subcommand)]
        command: ServerCommands,
    },
}

impl Commands {
    /// dispatcher for top level commands
    pub(crate) fn dispatch(
        &self,
        client: &pdns_client::Client,
    ) -> Result<(), Box<dyn std::error::Error>> {
        match self {
            Self::Servers { command } => {
                command.dispatch(client)?;
            }
        }

        Ok(())
    }
}