devmatteini/pihole-switch

pihole - override default server host

Closed this issue · 1 comments

The pihole url used for making requests in prod is

pub const PIHOLE_API_URL: &str = "http://pi.hole/admin/api.php";

This implied that the device in which pihole-switch is used, has the pihole server set as the dns in order to resolve http://pi.hole/.
If it's not the case all the requests will fail.

It should be possible to override the default host, by passing the host's IPv4/hostname and then internally build the full url such as http://192.168.1.15/admin/api.php where 192.168.1.15 is the parameter passed to override the default one.

API

Must refactor PiHoleConfig::new ctor to allow to pass the full url.
It should also be provided another method to build the full url sush as

fn build_url(host: &str) -> String

CLI

Right now there are only commands, so the Cli is just a sum type (enum).

It must be converted to a struct in order to add a global option

#[derive(StructOpt)]
pub struct Cli {
    #[structopt(short = "H", long = "host")]
    host: Option<String>,

    #[structopt(subcommand)]
    cmd: Commands, // Commands is the current Cli enum
}

See https://docs.rs/structopt/0.3.20/structopt/#subcommands