From 9e02688ced1ea3b00713d4237bad1d12f548d76d Mon Sep 17 00:00:00 2001 From: splurf Date: Tue, 16 Jan 2024 14:03:48 -0500 Subject: [PATCH] fixed `--help` flag output --- src/cfg.rs | 16 +++++++++++----- src/main.rs | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cfg.rs b/src/cfg.rs index 2c7ff85..8ac405b 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -15,7 +15,7 @@ use { #[derive(Parser)] #[command(author, version, about)] -struct Config { +pub struct Config { #[arg(short, long)] email: String, @@ -32,6 +32,12 @@ struct Config { delay: Duration, } +impl Default for Config { + fn default() -> Self { + Self::parse() + } +} + pub struct BaseClient { client: Client, body: Body, @@ -46,15 +52,15 @@ impl BaseClient { PublicIpAPI::Ifconfig, ]; - pub fn setup() -> Result { - let Config { + pub fn setup( + Config { email, api_token, zone_id, id, delay, - } = Config::parse(); - + }: Config, + ) -> Result { let client = Client::default(); let builder_fn = Box::new(move |method: Method, client: &Client| -> RequestBuilder { client diff --git a/src/main.rs b/src/main.rs index 108c719..abb99fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,8 @@ mod util; use {cfg::*, err::*, util::*}; fn main() -> Result<()> { - let mut client = dbg("Initializing client", || BaseClient::setup())?; + let cfg = Config::default(); + let mut client = dbg("Initializing client", || BaseClient::setup(cfg))?; loop { match dbg("Doing routine", || routine(&mut client)) {