bunny-api 0.0.5

Alpha API client for Bunny.net
Documentation
use bunny_api::Client;
use clap::Parser;

pub mod edge;
pub mod purge;
pub mod support;

#[derive(Debug, Parser)]
pub struct Common {
    /// The API key found at <https://panel.bunny.net/account>.
    #[clap(long, env)]
    access_key: String,
}

impl Common {
    pub fn client(&self) -> Result<Client, bunny_api::ClientError> {
        Client::new(&self.access_key)
    }
}

#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub enum Error {
    Edge(#[from] edge::Error),
    Purge(#[from] purge::Error),
    Support(#[from] support::Error),
}

#[derive(Debug, Parser)]
pub enum Cli {
    #[clap(subcommand)]
    Edge(edge::Cli),
    Purge(purge::Cli),
    #[clap(subcommand)]
    Support(support::Cli),
}

impl Cli {
    pub async fn run(self) -> Result<(), Error> {
        match self {
            Self::Edge(edge) => edge.run().await?,
            Self::Purge(purge) => purge.run().await?,
            Self::Support(support) => support.run().await?,
        }

        Ok(())
    }
}