docs: added documentation, enforced documentation
All checks were successful
CI / build (push) Successful in 7m21s
All checks were successful
CI / build (push) Successful in 7m21s
This commit is contained in:
@@ -26,6 +26,7 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper managing contexts
|
||||
pub struct ContextManager {
|
||||
context: RwLock<Arc<Context>>,
|
||||
config_path: PathBuf,
|
||||
@@ -67,10 +68,12 @@ impl ContextManager {
|
||||
})
|
||||
}
|
||||
|
||||
/// Obtain current ContextManager configuration
|
||||
pub fn get_config(&self) -> std::sync::RwLockReadGuard<'_, Config> {
|
||||
self.config.read().unwrap()
|
||||
}
|
||||
|
||||
/// Make a ContextManager using a specific configuration path
|
||||
pub fn with_path(path: PathBuf) -> Self {
|
||||
let config = Config::default();
|
||||
Self {
|
||||
@@ -80,6 +83,7 @@ impl ContextManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Save current context configuration to disk
|
||||
pub fn save(&self) -> io::Result<()> {
|
||||
let config = self.config.read().unwrap();
|
||||
let content = serde_json::to_string_pretty(&*config)
|
||||
@@ -97,6 +101,7 @@ impl ContextManager {
|
||||
Context::new(context_config)
|
||||
}
|
||||
|
||||
/// List contexts from configuration
|
||||
pub fn list_contexts(&self) -> Vec<String> {
|
||||
self.config
|
||||
.read()
|
||||
@@ -107,6 +112,7 @@ impl ContextManager {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Add a context to configuration
|
||||
pub fn add_context(&self, name: &str, config: ContextConfig) -> io::Result<()> {
|
||||
self.config
|
||||
.write()
|
||||
@@ -116,6 +122,7 @@ impl ContextManager {
|
||||
self.save()
|
||||
}
|
||||
|
||||
/// Remove context from configuration
|
||||
pub fn remove_context(&self, name: &str) -> io::Result<()> {
|
||||
let mut config = self.config.write().unwrap();
|
||||
if name == "local" {
|
||||
@@ -137,6 +144,7 @@ impl ContextManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set current context from name (modifying configuration)
|
||||
pub fn set_current(&self, name: &str) -> io::Result<()> {
|
||||
let mut config = self.config.write().unwrap();
|
||||
if config.contexts.contains_key(name) {
|
||||
@@ -153,14 +161,18 @@ impl ContextManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set current context, without modifying configuration
|
||||
pub fn set_current_ephemeral(&self, context: Context) {
|
||||
*self.context.write().unwrap() = context.into();
|
||||
}
|
||||
|
||||
/// Obtain current context handle
|
||||
pub fn current(&self) -> Arc<Context> {
|
||||
self.context.read().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Obtain current context name
|
||||
/// Will not work for ephemeral context (obtained from config)
|
||||
pub fn current_name(&self) -> String {
|
||||
self.config.read().unwrap().context.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user