pub struct Context { /* private fields */ }Expand description
Manages ClickHouse connection profiles.
Profiles are persisted in a TOML file, while credentials are stored securely in the system keyring.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
config_path: Option<&PathBuf>,
override_name: Option<&str>,
) -> Result<Self, ContextError>
pub fn new( config_path: Option<&PathBuf>, override_name: Option<&str>, ) -> Result<Self, ContextError>
Constructs a new Context by reading a config file or creating a default config.
config_path: Optional path to a custom config file.override_name: Optional profile name to use instead of the default.
Returns an error if the path is invalid or the profile does not exist.
Sourcepub fn active_profile_name(&self) -> Option<&str>
pub fn active_profile_name(&self) -> Option<&str>
Returns the name of the currently active profile, either the overridden (see Context::new) one,
or the default profile from the config.
Sourcepub fn profile(&self) -> Result<Option<ContextProfile>, ContextError>
pub fn profile(&self) -> Result<Option<ContextProfile>, ContextError>
Returns the currently active profile, if available.
Sourcepub fn set_profile(
&mut self,
profile: ContextProfile,
name: &str,
) -> Result<(), ContextError>
pub fn set_profile( &mut self, profile: ContextProfile, name: &str, ) -> Result<(), ContextError>
Adds or updates a profile with the given name, storing the password securely.
Writes the config to disk after setting.
Sourcepub fn delete_profile(&mut self, name: &str) -> Result<(), ContextError>
pub fn delete_profile(&mut self, name: &str) -> Result<(), ContextError>
Delete a profile with the given name.
Writes the config to disk after setting.
Sourcepub fn set_default(&mut self, name: &str) -> Result<(), ContextError>
pub fn set_default(&mut self, name: &str) -> Result<(), ContextError>
Sets the given profile as the default (used if no --context is provided).
Returns an error if the profile does not exist.
Sourcepub fn get_profile(&self, name: &str) -> Result<ContextProfile, ContextError>
pub fn get_profile(&self, name: &str) -> Result<ContextProfile, ContextError>
Loads a profile by name and fills in its password from the system keyring.
Sourcepub fn get_config_path(&self) -> &PathBuf
pub fn get_config_path(&self) -> &PathBuf
Returns the resolved path to the config file used by this context.