From 93e5570293549da8958dafad45a416a01a34a45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Sat, 20 Dec 2025 08:52:34 +0100 Subject: [PATCH] use human_units for Duration params --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/bin/dkl.rs | 18 +++++++++--------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e4de31..92ee109 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,6 +279,7 @@ dependencies = [ "futures-util", "glob", "hex", + "human-units", "log", "lz4", "nix", @@ -586,6 +587,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "human-units" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47cf34dbcbbb7f1f6589c18e26f15a5a72592750dd5472037eb78fc0f92020d4" +dependencies = [ + "paste", +] + [[package]] name = "hyper" version = "1.8.1" @@ -1059,6 +1069,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "percent-encoding" version = "2.3.2" diff --git a/Cargo.toml b/Cargo.toml index 42125dc..edc4666 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ futures = "0.3.31" futures-util = "0.3.31" glob = "0.3.2" hex = "0.4.3" +human-units = "0.5.3" log = "0.4.27" lz4 = "1.28.1" nix = { version = "0.30.1", features = ["user"] } diff --git a/src/bin/dkl.rs b/src/bin/dkl.rs index 3c8b1c7..cbe4f19 100644 --- a/src/bin/dkl.rs +++ b/src/bin/dkl.rs @@ -1,8 +1,8 @@ use clap::{CommandFactory, Parser, Subcommand}; use eyre::{format_err, Result}; +use human_units::Duration; use log::{debug, error}; use std::net::SocketAddr; -use std::time::Duration; use tokio::fs; #[derive(Parser)] @@ -71,12 +71,12 @@ enum Command { #[arg(long, short = 'l')] listen: Vec, targets: Vec, - /// target polling interval, in seconds - #[arg(long, default_value = "30")] - poll: u16, - /// connect or check timeout, in seconds - #[arg(long, default_value = "5")] - timeout: u16, + /// target polling interval + #[arg(long, default_value = "30s")] + poll: Duration, + /// connect or check timeout + #[arg(long, default_value = "5s")] + timeout: Duration, }, } @@ -147,8 +147,8 @@ async fn main() -> Result<()> { } => Ok(dkl::proxy::Proxy { listen_addrs: listen, targets, - poll: Duration::from_secs(poll.into()), - timeout: Duration::from_secs(timeout.into()), + poll: poll.into(), + timeout: timeout.into(), } .run() .await