Use the humantime crate to parse Duration

This commit is contained in:
finga 2021-06-27 02:39:22 +02:00
parent 851a387c82
commit 83e4ff36e5
8 changed files with 18 additions and 29 deletions

View file

@ -1,7 +1,7 @@
use crate::utils;
use anyhow::Result;
use chrono::{DateTime, Local};
use clap::Clap;
use humantime::Duration;
use posixmq::PosixMq;
use std::str;
@ -17,7 +17,7 @@ pub struct Recv {
/// Print a timestamp before each message
#[clap(short, long)]
pub timestamp: bool,
/// Timeout in "<timeout>[s]" (default) or "<timeout>ms"
/// Timeout, example "5h 23min 42ms"
#[clap(short = 'o', long, conflicts_with = "deadline")]
pub timeout: Option<String>,
/// Deadline until messages are received (format: "%Y-%m-%d %H:%M:%S")
@ -45,7 +45,7 @@ impl Recv {
let mut buf = vec![0; mq.attributes()?.max_msg_len];
if let Some(timeout) = &self.timeout {
let (prio, len) = mq.recv_timeout(&mut buf, utils::parse_duration(timeout)?)?;
let (prio, len) = mq.recv_timeout(&mut buf, *timeout.parse::<Duration>()?)?;
print_message(verbose, prio, len, self.timestamp, str::from_utf8(&buf)?);
} else if let Some(deadline) = &self.deadline {