diff --git a/Cargo.lock b/Cargo.lock index fcb3a2b..3e6cbd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1450,6 +1450,16 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "humantime-serde" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c" +dependencies = [ + "humantime", + "serde", +] + [[package]] name = "hyper" version = "0.14.19" @@ -1745,6 +1755,7 @@ dependencies = [ "headers", "http", "humantime", + "humantime-serde", "indicatif", "log", "lychee-lib", diff --git a/fixtures/configs/smoketest.toml b/fixtures/configs/smoketest.toml index a1edc73..73b6486 100644 --- a/fixtures/configs/smoketest.toml +++ b/fixtures/configs/smoketest.toml @@ -17,8 +17,7 @@ no_progress = true cache = false # Discard all cached requests older than this duration. -# Error: invalid type: string "2d", expected struct Duration for key `max_cache_age` -# max_cache_age = "2d" +max_cache_age = "2d" ############################# Runtime ############################# @@ -69,8 +68,7 @@ headers = [] remap = [ "https://example.com http://example.invalid" ] # Base URL or website root directory to check relative URLs. -# Error: invalid type: unit variant, expected newtype variant for key `base` -# base = "https://example.com" +base = "https://example.com" # HTTP basic auth support. This will be the username and password passed to the # authorization HTTP header. See diff --git a/lychee-bin/Cargo.toml b/lychee-bin/Cargo.toml index 7dd1d8a..dd8c106 100644 --- a/lychee-bin/Cargo.toml +++ b/lychee-bin/Cargo.toml @@ -45,6 +45,7 @@ once_cell = "1.12.0" dashmap = { version = "5.3.4", features = ["serde"] } csv = "1.1.6" humantime = "2.1.0" +humantime-serde = "1.1.1" secrecy = { version = "0.8.0", features = ["serde"] } supports-color = "1.3.0" log = "0.4.17" diff --git a/lychee-bin/src/options.rs b/lychee-bin/src/options.rs index 1c4d7c0..f30b5a9 100644 --- a/lychee-bin/src/options.rs +++ b/lychee-bin/src/options.rs @@ -165,6 +165,7 @@ pub(crate) struct Config { default_value = &MAX_CACHE_AGE_STR )] #[serde(default = "max_cache_age")] + #[serde(with = "humantime_serde")] pub(crate) max_cache_age: Duration, /// Don't perform any link checking. diff --git a/lychee-lib/src/types/base.rs b/lychee-lib/src/types/base.rs index 0c550db..e300f3a 100644 --- a/lychee-lib/src/types/base.rs +++ b/lychee-lib/src/types/base.rs @@ -9,6 +9,7 @@ use crate::{ErrorKind, InputSource}; /// Both, local and remote targets are supported. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] #[allow(variant_size_differences)] +#[serde(try_from = "&str")] pub enum Base { /// Local file path pointing to root directory Local(PathBuf), diff --git a/lychee.example.toml b/lychee.example.toml index ff48f21..7792b70 100644 --- a/lychee.example.toml +++ b/lychee.example.toml @@ -16,8 +16,7 @@ output = "report.md" cache = true # Discard all cached requests older than this duration. -# Error: invalid type: string "2d", expected struct Duration for key `max_cache_age` -# max_cache_age = "2d" +max_cache_age = "2d" ############################# Runtime ############################# @@ -68,8 +67,7 @@ headers = [] remap = [ "https://example.com http://example.invalid" ] # Base URL or website root directory to check relative URLs. -# Error: invalid type: unit variant, expected newtype variant for key `base` -# base = "https://example.com" +base = "https://example.com" # HTTP basic auth support. This will be the username and password passed to the # authorization HTTP header. See