claude_code_switcher/
lib.rs

1//! Claude Code Switcher - Modular CLI tool for managing Claude Code settings
2//!
3//! This library provides a modular architecture for managing Claude Code settings
4//! across multiple AI providers through templates and snapshots.
5
6pub mod cli;
7pub mod commands;
8pub mod credentials;
9pub mod settings;
10pub mod snapshots;
11pub mod templates;
12pub mod utils;
13
14// Re-export key types for convenience
15pub use cli::{Cli, Commands, CredentialCommands};
16pub use commands::run_command;
17pub use credentials::{
18    CredentialStore, SavedCredential, SavedCredentialStore, get_api_key_interactively,
19};
20pub use settings::{
21    ClaudeSettings, Hooks, Permissions, StatusLine, format_settings_for_display, merge_settings,
22};
23pub use snapshots::{Snapshot, SnapshotScope, SnapshotStore};
24pub use templates::{TemplateType, get_all_templates, get_template, get_template_type};
25pub use utils::{get_credentials_dir, get_snapshots_dir};
26
27// Core traits for abstraction
28pub trait Configurable: Sized {
29    /// Merge this configuration with another, with priority given to self
30    fn merge_with(self, other: Self) -> Self;
31
32    /// Filter settings by the specified scope
33    fn filter_by_scope(self, scope: &SnapshotScope) -> Self;
34
35    /// Mask sensitive data for display purposes
36    fn mask_sensitive_data(self) -> Self;
37}
38
39pub trait Storage<T>: Send + Sync {
40    /// Load data from storage
41    fn load(&self) -> anyhow::Result<T>;
42
43    /// Save data to storage
44    fn save(&self, data: &T) -> anyhow::Result<()>;
45
46    /// Get the storage path
47    fn path(&self) -> std::path::PathBuf;
48}
49
50pub trait CredentialManager: Send + Sync {
51    /// Save a credential
52    fn save_credential(
53        &self,
54        name: String,
55        api_key: &str,
56        template_type: TemplateType,
57    ) -> anyhow::Result<()>;
58
59    /// Load all stored credentials
60    fn load_credentials(&self) -> anyhow::Result<Vec<SavedCredential>>;
61
62    /// Delete a credential by ID
63    fn delete_credential(&self, id: &str) -> anyhow::Result<()>;
64
65    /// Clear all credentials
66    fn clear_credentials(&self) -> anyhow::Result<()>;
67}