From 3fe71ed15b9013745cc3bcec8af18640c2459f9e Mon Sep 17 00:00:00 2001 From: splurf Date: Tue, 16 Jan 2024 13:53:41 -0500 Subject: [PATCH] added `delay` arg --- src/cfg.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cfg.rs b/src/cfg.rs index 0973481..2c7ff85 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -4,15 +4,16 @@ use { json::{Body, DnsRecord, DnsRecordResult, PublicIpAPI}, }, clap::Parser, + humantime::parse_duration, reqwest::{ blocking::{Client, RequestBuilder}, header::CONTENT_TYPE, Method, }, - std::net::IpAddr, + std::{net::IpAddr, thread::sleep, time::Duration}, }; -#[derive(Parser, Debug)] +#[derive(Parser)] #[command(author, version, about)] struct Config { #[arg(short, long)] @@ -26,12 +27,16 @@ struct Config { #[arg(short, long)] id: String, + + #[arg(short, long, value_parser = parse_duration, default_value = "5min")] + delay: Duration, } pub struct BaseClient { client: Client, body: Body, builder_fn: Box RequestBuilder>, + delay: Duration, } impl BaseClient { @@ -47,7 +52,9 @@ impl BaseClient { api_token, zone_id, id, + delay, } = Config::parse(); + let client = Client::default(); let builder_fn = Box::new(move |method: Method, client: &Client| -> RequestBuilder { client @@ -68,6 +75,7 @@ impl BaseClient { client, body, builder_fn, + delay, }) } @@ -94,6 +102,10 @@ impl BaseClient { .ok_or(Error::API) } + pub fn delay(&self) { + sleep(self.delay) + } + fn request( method: Method, client: &Client,