Use duration syntax for CLI timeout options as well

This commit is contained in:
timvisee 2019-11-04 17:43:51 +01:00
parent e9a2b715d1
commit 53649ebbb3
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
2 changed files with 20 additions and 19 deletions

View file

@ -25,6 +25,7 @@ use crate::config::{CLIENT_TIMEOUT, CLIENT_TRANSFER_TIMEOUT};
use crate::util::app_history_file_path_string;
#[cfg(feature = "infer-command")]
use crate::util::bin_name;
use crate::util::parse_duration;
#[cfg(feature = "history")]
lazy_static! {
@ -100,13 +101,13 @@ impl<'a: 'b, 'b> Handler<'a> {
.hide_default_value(true)
.env("FFSEND_TIMEOUT")
.hide_env_values(true)
.validator(|arg| arg
.parse::<u64>()
.map(|_| ())
.map_err(|_| String::from(
"Timeout time must be a positive number of seconds, or 0 to disable."
))
),
.validator(|arg| {
parse_duration(&arg).map(drop).map_err(|_| {
String::from(
"Timeout time must be a positive number of seconds, or 0 to disable."
)
})
}),
)
.arg(
Arg::with_name("transfer-timeout")
@ -125,13 +126,13 @@ impl<'a: 'b, 'b> Handler<'a> {
.hide_default_value(true)
.env("FFSEND_TRANSFER_TIMEOUT")
.hide_env_values(true)
.validator(|arg| arg
.parse::<u64>()
.map(|_| ())
.map_err(|_| String::from(
"Timeout time must be a positive number of seconds, or 0 to disable."
))
),
.validator(|arg| {
parse_duration(&arg).map(drop).map_err(|_| {
String::from(
"Timeout time must be a positive number of seconds, or 0 to disable."
)
})
}),
)
.arg(
Arg::with_name("quiet")

View file

@ -6,7 +6,7 @@ use ffsend_api::api::DesiredVersion;
use super::Matcher;
use crate::cmd::arg::{ArgApi, ArgBasicAuth, CmdArgOption};
use crate::util::env_var_present;
use crate::util::{env_var_present, parse_duration};
#[cfg(feature = "history")]
use crate::util::{quit_error_msg, ErrorHintsBuilder};
@ -65,16 +65,16 @@ impl<'a: 'b, 'b> MainMatcher<'a> {
pub fn timeout(&self) -> u64 {
self.matches
.value_of("timeout")
.and_then(|arg| arg.parse().ok())
.expect("invalid timeout value")
.and_then(|arg| parse_duration(arg).ok())
.expect("invalid timeout value") as u64
}
/// Get the transfer timeout in seconds
pub fn transfer_timeout(&self) -> u64 {
self.matches
.value_of("transfer-timeout")
.and_then(|arg| arg.parse().ok())
.expect("invalid transfer-timeout value")
.and_then(|arg| parse_duration(arg).ok())
.expect("invalid transfer-timeout value") as u64
}
/// Check whether we are incognito from the file history.