use human_units for Duration params

This commit is contained in:
Mikaël Cluseau
2025-12-20 08:52:34 +01:00
parent fb3f8942d4
commit 93e5570293
3 changed files with 26 additions and 9 deletions

16
Cargo.lock generated
View File

@ -279,6 +279,7 @@ dependencies = [
"futures-util", "futures-util",
"glob", "glob",
"hex", "hex",
"human-units",
"log", "log",
"lz4", "lz4",
"nix", "nix",
@ -586,6 +587,15 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" 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]] [[package]]
name = "hyper" name = "hyper"
version = "1.8.1" version = "1.8.1"
@ -1059,6 +1069,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.2" version = "2.3.2"

View File

@ -24,6 +24,7 @@ futures = "0.3.31"
futures-util = "0.3.31" futures-util = "0.3.31"
glob = "0.3.2" glob = "0.3.2"
hex = "0.4.3" hex = "0.4.3"
human-units = "0.5.3"
log = "0.4.27" log = "0.4.27"
lz4 = "1.28.1" lz4 = "1.28.1"
nix = { version = "0.30.1", features = ["user"] } nix = { version = "0.30.1", features = ["user"] }

View File

@ -1,8 +1,8 @@
use clap::{CommandFactory, Parser, Subcommand}; use clap::{CommandFactory, Parser, Subcommand};
use eyre::{format_err, Result}; use eyre::{format_err, Result};
use human_units::Duration;
use log::{debug, error}; use log::{debug, error};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::time::Duration;
use tokio::fs; use tokio::fs;
#[derive(Parser)] #[derive(Parser)]
@ -71,12 +71,12 @@ enum Command {
#[arg(long, short = 'l')] #[arg(long, short = 'l')]
listen: Vec<SocketAddr>, listen: Vec<SocketAddr>,
targets: Vec<SocketAddr>, targets: Vec<SocketAddr>,
/// target polling interval, in seconds /// target polling interval
#[arg(long, default_value = "30")] #[arg(long, default_value = "30s")]
poll: u16, poll: Duration,
/// connect or check timeout, in seconds /// connect or check timeout
#[arg(long, default_value = "5")] #[arg(long, default_value = "5s")]
timeout: u16, timeout: Duration,
}, },
} }
@ -147,8 +147,8 @@ async fn main() -> Result<()> {
} => Ok(dkl::proxy::Proxy { } => Ok(dkl::proxy::Proxy {
listen_addrs: listen, listen_addrs: listen,
targets, targets,
poll: Duration::from_secs(poll.into()), poll: poll.into(),
timeout: Duration::from_secs(timeout.into()), timeout: timeout.into(),
} }
.run() .run()
.await .await