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