From fe230a30caaefd380ce577af5307b8f11eaf84d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ko=C5=82aczkowski?= Date: Fri, 5 Jul 2024 16:53:20 +0200 Subject: [PATCH] Use Option for datacenter to keep backwards compatibility Adding non-optional datacenter field to the config made it impossible to load old reports. --- src/config.rs | 4 ++-- src/context.rs | 3 +-- src/report.rs | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3daf29c..a1501bc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -182,8 +182,8 @@ pub struct ConnectionConf { pub ssl_key_file: Option, /// Datacenter name - #[clap(long("datacenter"), required = false, default_value = "")] - pub datacenter: String, + #[clap(long("datacenter"), required = false)] + pub datacenter: Option, /// Default CQL query consistency level #[clap(long("consistency"), required = false, default_value = "LOCAL_QUORUM")] diff --git a/src/context.rs b/src/context.rs index e96eb20..23a560e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -62,8 +62,7 @@ fn ssl_context(conf: &&ConnectionConf) -> Result, CassError> /// Configures connection to Cassandra. pub async fn connect(conf: &ConnectionConf) -> Result { let mut policy_builder = DefaultPolicy::builder().token_aware(true); - let dc = &conf.datacenter; - if !dc.is_empty() { + if let Some(dc) = &conf.datacenter { policy_builder = policy_builder .prefer_datacenter(dc.to_owned()) .permit_dc_failover(true); diff --git a/src/report.rs b/src/report.rs index ba8165d..cfed4f9 100644 --- a/src/report.rs +++ b/src/report.rs @@ -512,7 +512,9 @@ impl<'a> Display for RunConfigCmp<'a> { } let lines: Vec> = vec![ - self.line("Datacenter", "", |conf| conf.connection.datacenter.clone()), + self.line("Datacenter", "", |conf| { + conf.connection.datacenter.clone().unwrap_or_default() + }), self.line("Consistency", "", |conf| { conf.connection.consistency.scylla_consistency().to_string() }),