From 0a6012b57b39673e4f9a5c95c34d648f857e55fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20B=C3=BCsch?= Date: Sat, 8 Oct 2022 07:46:08 +1100 Subject: [PATCH] fix(console): make `retain_for` default to 6s if not specfied (#383) Fixes #382 --- tokio-console/src/config.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 52f0b4448..675953b9d 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -121,6 +121,12 @@ pub enum OptionalCmd { #[derive(Debug, Clone, Copy, Deserialize)] struct RetainFor(Option); +impl Default for RetainFor { + fn default() -> Self { + Self(Some(Duration::from_secs(6))) + } +} + impl fmt::Display for RetainFor { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { @@ -320,7 +326,7 @@ impl Config { } pub(crate) fn retain_for(&self) -> Option { - self.retain_for.as_ref().and_then(|value| value.0) + self.retain_for.unwrap_or_default().0 } pub(crate) fn target_addr(&self) -> Uri { @@ -390,7 +396,7 @@ impl Default for Config { target_addr: Some(default_target_addr()), env_filter: Some(tracing_subscriber::EnvFilter::new("off")), log_directory: Some(default_log_directory()), - retain_for: Some(RetainFor(Some(Duration::from_secs(6)))), + retain_for: Some(RetainFor::default()), view_options: ViewOptions::default(), subcmd: None, }