Skip to main content

ConfigStorage

Struct ConfigStorage 

Source
pub struct ConfigStorage {
    pub configurations: BTreeMap<String, Configuration>,
    pub claude_settings_dir: Option<String>,
    pub default_storage_mode: Option<StorageMode>,
    pub codex_configurations: Option<BTreeMap<String, CodexConfiguration>>,
}
Expand description

Storage manager for Claude API configurations

Handles persistence and retrieval of multiple API configurations stored in ~/.cc_auto_switch/configurations.json

Fields§

§configurations: BTreeMap<String, Configuration>

Map of alias names to configuration objects

§claude_settings_dir: Option<String>

Custom directory for Claude settings (optional)

§default_storage_mode: Option<StorageMode>

Default storage mode for writing configurations (None = use env mode)

§codex_configurations: Option<BTreeMap<String, CodexConfiguration>>

Codex (OpenAI) configurations, stored separately from Claude configurations

Implementations§

Source§

impl ConfigStorage

Source

pub fn add_codex_configuration(&mut self, config: CodexConfiguration)

Add a Codex configuration to storage

Overwrites existing configuration with the same alias.

Source

pub fn get_codex_configuration( &self, alias_name: &str, ) -> Option<&CodexConfiguration>

Get a Codex configuration by alias name

Source

pub fn remove_codex_configuration(&mut self, alias_name: &str) -> bool

Remove a Codex configuration by alias name

Returns true if a configuration was found and removed, false otherwise.

Source

pub fn update_codex_configuration( &mut self, old_alias: &str, new_config: CodexConfiguration, ) -> Result<()>

Update a Codex configuration by old alias name

If the alias changed, removes the old entry and inserts the new one. Returns error if the old configuration doesn’t exist.

Source§

impl ConfigStorage

Source

pub fn load() -> Result<Self>

Load configurations from disk

Reads the JSON file from ~/.claude/cc_auto_switch_setting.json Auto-migrates from old location ~/.cc-switch/configurations.json if it exists Returns default empty storage if file doesn’t exist

§Errors

Returns error if file exists but cannot be read or parsed

Source

pub fn save(&self) -> Result<()>

Save configurations to disk

Writes the current state to ~/.claude/cc_auto_switch_setting.json Creates the directory structure if it doesn’t exist

§Errors

Returns error if directory cannot be created or file cannot be written

Source

pub fn migrate_from_old_path() -> Result<()>

Migrate configurations from old path to new path

Old path: ~/.cc_auto_switch/configurations.json New path: ~/.claude/cc_auto_switch_setting.json

Safe to run multiple times. If old path does not exist, returns Ok(()) and prints a note.

Source

pub fn add_configuration(&mut self, config: Configuration)

Add a new configuration to storage

§Arguments
  • config - Configuration object to add

Overwrites existing configuration with same alias

Source

pub fn remove_configuration(&mut self, alias_name: &str) -> bool

Remove a configuration by alias name

§Arguments
  • alias_name - Name of configuration to remove
§Returns

true if configuration was found and removed, false if not found

Source

pub fn get_configuration(&self, alias_name: &str) -> Option<&Configuration>

Get a configuration by alias name

§Arguments
  • alias_name - Name of configuration to retrieve
§Returns

Some(&Configuration) if found, None if not found

Source

pub fn set_claude_settings_dir(&mut self, directory: String)

Set the default directory for Claude settings

§Arguments
  • directory - Directory path for Claude settings
Source

pub fn get_claude_settings_dir(&self) -> Option<&String>

Get the current Claude settings directory

§Returns

Some(&String) if custom directory is set, None if using default

Source

pub fn update_configuration( &mut self, old_alias: &str, new_config: Configuration, ) -> Result<()>

Update an existing configuration

This method handles updating a configuration, including potential alias renaming. If the new configuration has a different alias name than the old one, it removes the old entry and creates a new one.

§Arguments
  • old_alias - Current alias name of the configuration to update
  • new_config - Updated configuration object
§Returns

Ok(()) if update succeeds, Err if the old configuration doesn’t exist

§Errors

Returns error if the configuration with old_alias doesn’t exist

Trait Implementations§

Source§

impl Default for ConfigStorage

Source§

fn default() -> ConfigStorage

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ConfigStorage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ConfigStorage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,