diff --git a/Cargo.lock b/Cargo.lock index 6a3864a..0599a07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,6 +443,15 @@ dependencies = [ "darling_macro 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "darling" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "darling_core 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "darling_macro 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "darling_core" version = "0.6.3" @@ -468,6 +477,19 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "darling_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "darling_macro" version = "0.6.3" @@ -488,6 +510,16 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "darling_macro" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "darling_core 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "derive_builder" version = "0.6.0" @@ -512,6 +544,18 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "derive_builder" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "darling 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_builder_core 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "derive_builder_core" version = "0.3.0" @@ -534,6 +578,17 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "derive_builder_core" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "darling 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.8.1" @@ -641,7 +696,7 @@ dependencies = [ "derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ffsend-api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ffsend-api 0.4.0 (git+https://github.com/timvisee/ffsend-api.git?tag=v0.4.0)", "fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -656,7 +711,6 @@ dependencies = [ "tar 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "took 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "urlshortener 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "version-compare 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -664,15 +718,15 @@ dependencies = [ [[package]] name = "ffsend-api" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.4.0" +source = "git+https://github.com/timvisee/ffsend-api.git?tag=v0.4.0#83a06edd55f61408d7a090a1980d921b19cdd43b" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_builder 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hkdf 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -689,7 +743,7 @@ dependencies = [ "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "version-compare 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "version-compare 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "websocket 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1811,6 +1865,11 @@ name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "strsim" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "subtle" version = "1.0.0" @@ -2079,11 +2138,6 @@ dependencies = [ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "took" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "traitobject" version = "0.1.0" @@ -2219,6 +2273,11 @@ name = "version-compare" version = "0.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version-compare" +version = "0.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.5" @@ -2404,16 +2463,21 @@ dependencies = [ "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37519ccdfd73a75821cac9319d4fce15a81b9fcf75f951df5b9988aa3a0af87d" "checksum csv-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9b5cadb6b25c77aeff80ba701712494213f4a8418fcda2ee11b6560c3ad0bf4c" +"checksum darling 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe629a532efad5526454efb0700f86d5ad7ff001acb37e431c8bf017a432a8e" "checksum darling 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "49fc76d30c96cc0bdc8b966968e6535d900f3e42c56204d355192a670d989c6e" "checksum darling 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fcfbcb0c5961907597a7d1148e3af036268f2b773886b8bb3eeb1e1281d3d3d6" +"checksum darling_core 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ee54512bec54b41cf2337a22ddfadb53c7d4c738494dc2a186d7b037ad683b85" "checksum darling_core 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d844ad185d7f9bfd072914584649741768151c4131f6ae59f282889f7a1e450" "checksum darling_core 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6afc018370c3bff3eb51f89256a6bdb18b4fdcda72d577982a14954a7a0b402c" +"checksum darling_macro 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cd3e432e52c0810b72898296a69d66b1d78d1517dff6cde7a130557a55a62c1" "checksum darling_macro 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "280207f9bd6f6fd58acd08ed722fb9a75412ad9b1fd9b6a8fbfc55410aca2c2c" "checksum darling_macro 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d8dac1c6f1d29a41c4712b4400f878cb4fcc4c7628f298dd75038e024998d1" "checksum derive_builder 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "583a8f76cd41ae6303aca0db4539b90b4fcb289f75467d0c3905781dc670621b" "checksum derive_builder 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac53fa6a3cda160df823a9346442525dcaf1e171999a1cf23e67067e4fd64d4" +"checksum derive_builder 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfbc80e9c3b77201f32c9541b13d9678388782272554af7e65103310265462e6" "checksum derive_builder_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb4e6b5fb126caa298af7f9b9719ad6301eb7dd1613fd7543a4e935cef46c07" "checksum derive_builder_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0288a23da9333c246bb18c143426074a6ae96747995c5819d2947b64cd942b37" +"checksum derive_builder_core 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b68a4fe580fdda1bf3860b2360b9020696d42fc58f2343cf4be2faedf74c5a9" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c" "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" @@ -2426,7 +2490,7 @@ dependencies = [ "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum ffsend-api 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "87eed426eddc1604be1577d86df45daf2f2a8492cb2acaff1e9b445e0abdfc0d" +"checksum ffsend-api 0.4.0 (git+https://github.com/timvisee/ffsend-api.git?tag=v0.4.0)" = "" "checksum filetime 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd7380b54ced79dda72ecc35cc4fbbd1da6bba54afaa37e96fd1c2a308cd469" "checksum flate2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" @@ -2555,6 +2619,7 @@ dependencies = [ "checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +"checksum strsim 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "032c03039aae92b350aad2e3779c352e104d919cb192ba2fabbd7b831ce4f0f6" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" @@ -2580,7 +2645,6 @@ dependencies = [ "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" "checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" "checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" -"checksum took 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ac67e206f47aaa05a26dac6b2cf79b4c07e3a038461070dbaed28a51fcab5f8" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" @@ -2600,6 +2664,7 @@ dependencies = [ "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum version-compare 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" "checksum version-compare 0.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "eb5129ec767786425be638b2fd9940cfe94ee6c26f80e723711fdfbde7380c7e" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" diff --git a/Cargo.toml b/Cargo.toml index 34fde51..54cf019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,7 +109,7 @@ colored = "1.8" derive_builder = "0.7" directories = "2.0" failure = "0.1" -ffsend-api = { version = "0.3.3", default-features = false } +ffsend-api = { version = "0.4", default-features = false } fs2 = "0.4" lazy_static = "1.0" open = "1" @@ -133,3 +133,8 @@ which = { version = "2.0", optional = true } [target.'cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd", target_os = "netbsd")))'.dependencies] # Aliased to clip to prevent name collision with clipboard feature clip = { version = "0.5", optional = true, package = "clipboard" } + +# TODO: remove before merging to master, when ffsend-api v0.4.0 is published +[patch.crates-io.ffsend-api] +git = "https://github.com/timvisee/ffsend-api.git" +tag = "v0.4.0" diff --git a/src/action/upload.rs b/src/action/upload.rs index 978306c..a1bf435 100644 --- a/src/action/upload.rs +++ b/src/action/upload.rs @@ -322,6 +322,7 @@ impl<'a> Upload<'a> { .download_limit(&matcher_main, api_version, auth) .map(|d| d as u8), ) + .expiry_time(matcher_upload.expiry_time(&matcher_main, api_version, auth)) .build() .unwrap(); diff --git a/src/cmd/arg/download_limit.rs b/src/cmd/arg/download_limit.rs index 633cf72..444984c 100644 --- a/src/cmd/arg/download_limit.rs +++ b/src/cmd/arg/download_limit.rs @@ -31,7 +31,7 @@ impl ArgDownloadLimit { .map(|value| format!("{}", value)) .collect::>() .join(", "); - eprintln!("The downloads limit must be one of: {}", allowed_str,); + eprintln!("The downloads limit must be one of: {}", allowed_str); if auth { eprintln!("Use '{}' to force", highlight("--force")); } else { diff --git a/src/cmd/arg/expiry_time.rs b/src/cmd/arg/expiry_time.rs new file mode 100644 index 0000000..b22e05a --- /dev/null +++ b/src/cmd/arg/expiry_time.rs @@ -0,0 +1,100 @@ +use clap::{Arg, ArgMatches}; +use ffsend_api::api::Version as ApiVersion; +use ffsend_api::config::expiry_max; + +use super::{CmdArg, CmdArgFlag, CmdArgOption}; +use crate::cmd::matcher::MainMatcher; +use crate::util::{highlight, prompt_yes, quit}; + +/// The download limit argument. +pub struct ArgExpiryTime {} + +impl ArgExpiryTime { + pub fn value_checked<'a>( + matches: &ArgMatches<'a>, + main_matcher: &MainMatcher, + api_version: ApiVersion, + auth: bool, + ) -> Option { + // Get the expiry time value + let mut expiry = Self::value(matches)?; + + // Get expiry time, return if allowed or when forcing + let allowed = expiry_max(api_version, auth); + if allowed.contains(&expiry) || main_matcher.force() { + return Some(expiry); + } + + // Prompt the user the specified expiry time is invalid + let allowed_str = allowed + .iter() + .map(|value| format!("{}", value)) + .collect::>() + .join(", "); + eprintln!("The expiry time must be one of: {}", allowed_str); + if auth { + eprintln!("Use '{}' to force", highlight("--force")); + } else { + eprintln!( + "Use '{}' to force, authenticate for higher limits", + highlight("--force") + ); + } + + // Ask to use closest limit, quit if user cancelled + let closest = closest(allowed, expiry); + if !prompt_yes( + &format!("Would you like to set expiry time to {} instead?", closest), + None, + main_matcher, + ) { + quit(); + } + expiry = closest; + + Some(expiry) + } +} + +impl CmdArg for ArgExpiryTime { + fn name() -> &'static str { + "expiry-time" + } + + fn build<'b, 'c>() -> Arg<'b, 'c> { + Arg::with_name("expiry-time") + .long("expiry-time") + .short("e") + .alias("expire") + .alias("expiry") + .value_name("TIME") + .help("The file expiry time") + } +} + +impl CmdArgFlag for ArgExpiryTime {} + +impl<'a> CmdArgOption<'a> for ArgExpiryTime { + type Value = Option; + + fn value<'b: 'a>(matches: &'a ArgMatches<'b>) -> Self::Value { + // TODO: do not unwrap, report an error + Self::value_raw(matches).map(|d| d.parse::().expect("invalid expiry time")) + } +} + +/// Find the closest value to `current` in the given `values` range. +fn closest(values: &[usize], current: usize) -> usize { + // Own the values, sort and reverse, start with biggest first + let mut values = values.to_vec(); + values.sort_unstable(); + + // Find the closest value, return it + *values + .iter() + .rev() + .map(|value| (value, (current as i64 - *value as i64).abs())) + .min_by_key(|value| value.1) + .expect("failed to find closest value, none given") + .0 +} diff --git a/src/cmd/arg/mod.rs b/src/cmd/arg/mod.rs index 8aa523e..9c5ca46 100644 --- a/src/cmd/arg/mod.rs +++ b/src/cmd/arg/mod.rs @@ -1,6 +1,7 @@ pub mod api; pub mod basic_auth; pub mod download_limit; +pub mod expiry_time; pub mod gen_passphrase; pub mod host; pub mod owner; @@ -11,6 +12,7 @@ pub mod url; pub use self::api::ArgApi; pub use self::basic_auth::ArgBasicAuth; pub use self::download_limit::ArgDownloadLimit; +pub use self::expiry_time::ArgExpiryTime; pub use self::gen_passphrase::ArgGenPassphrase; pub use self::host::ArgHost; pub use self::owner::ArgOwner; diff --git a/src/cmd/matcher/upload.rs b/src/cmd/matcher/upload.rs index b9a9d89..95eba2d 100644 --- a/src/cmd/matcher/upload.rs +++ b/src/cmd/matcher/upload.rs @@ -5,7 +5,10 @@ use ffsend_api::url::Url; use super::Matcher; use crate::cmd::{ - arg::{ArgDownloadLimit, ArgGenPassphrase, ArgHost, ArgPassword, CmdArgFlag, CmdArgOption}, + arg::{ + ArgDownloadLimit, ArgExpiryTime, ArgGenPassphrase, ArgHost, ArgPassword, CmdArgFlag, + CmdArgOption, + }, matcher::MainMatcher, }; use crate::util::{bin_name, env_var_present, quit_error_msg, ErrorHintsBuilder}; @@ -93,6 +96,18 @@ impl<'a: 'b, 'b> UploadMatcher<'a> { ) } + /// Get the expiry time in seconds. + /// + /// If the expiry time was not set, `None` is returned. + pub fn expiry_time( + &'a self, + main_matcher: &MainMatcher, + api_version: ApiVersion, + auth: bool, + ) -> Option { + ArgExpiryTime::value_checked(self.matches, main_matcher, api_version, auth) + } + /// Check whether to archive the file to upload. #[cfg(feature = "archive")] pub fn archive(&self) -> bool { diff --git a/src/cmd/subcmd/upload.rs b/src/cmd/subcmd/upload.rs index b62ad2d..80623ae 100644 --- a/src/cmd/subcmd/upload.rs +++ b/src/cmd/subcmd/upload.rs @@ -1,7 +1,8 @@ use clap::{App, Arg, SubCommand}; -use ffsend_api::action::params::PARAMS_DEFAULT_DOWNLOAD_STR as DOWNLOAD_DEFAULT; -use crate::cmd::arg::{ArgDownloadLimit, ArgGenPassphrase, ArgHost, ArgPassword, CmdArg}; +use crate::cmd::arg::{ + ArgDownloadLimit, ArgExpiryTime, ArgGenPassphrase, ArgHost, ArgPassword, CmdArg, +}; /// The upload command definition. pub struct CmdUpload; @@ -22,7 +23,8 @@ impl CmdUpload { ) .arg(ArgPassword::build().help("Protect the file with a password")) .arg(ArgGenPassphrase::build()) - .arg(ArgDownloadLimit::build().default_value(DOWNLOAD_DEFAULT)) + .arg(ArgDownloadLimit::build()) + .arg(ArgExpiryTime::build()) .arg(ArgHost::build()) .arg( Arg::with_name("name")