浏览代码

Use duration syntax for CLI timeout options as well

timvisee 5 年之前
父节点
当前提交
53649ebbb3
共有 2 个文件被更改,包括 20 次插入19 次删除
  1. 15 14
      src/cmd/handler.rs
  2. 5 5
      src/cmd/matcher/main.rs

+ 15 - 14
src/cmd/handler.rs

@@ -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")

+ 5 - 5
src/cmd/matcher/main.rs

@@ -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.