From e8f551cbadaae41048d49d9f0c75aa1f982fb31a Mon Sep 17 00:00:00 2001 From: Eguo Wang Date: Wed, 3 Jan 2024 16:39:28 +0800 Subject: [PATCH] refactor: change `ContextConfiguration::current()` function signature --- Cargo.toml | 2 +- src/config/context.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2d0fe98..e78f37f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "amp-common" description = "Rust libraries shared across Amphitheatre components and libraries" -version = "0.6.0" +version = "0.6.1" edition = "2021" license = "Apache-2.0" homepage = "https://amphitheatre.app" diff --git a/src/config/context.rs b/src/config/context.rs index 0a55e2d..ea152d6 100644 --- a/src/config/context.rs +++ b/src/config/context.rs @@ -58,11 +58,12 @@ impl ContextConfiguration { self.clusters.get(name) } - /// Get the current context. - pub fn current(&self) -> Option<&Cluster> { + /// Get the current context with name. + pub fn current(&self) -> Option<(String, Cluster)> { if let Some(name) = &self.current { - return self.clusters.get(name).to_owned(); + return Some((name.clone(), self.clusters.get(name).cloned().unwrap_or_default())); } + None } @@ -82,6 +83,11 @@ impl ContextConfiguration { self.clusters.iter() } + /// Get the list of clusters. + pub fn clusters(&self) -> &HashMap { + &self.clusters + } + /// Check if the context with the given name exists. pub fn exists(&self, name: &str) -> bool { self.clusters.contains_key(name)