package config import ( "fmt" "os" "path/filepath" ) // EnvConfigPath is the env var that, when set, overrides XDG lookup entirely. const EnvConfigPath = "CC_SWITCH_CONFIG" // ResolvePath returns the path cc-switch reads/writes. Precedence: // 1. CC_SWITCH_CONFIG (full path, used as-is) // 2. $XDG_CONFIG_HOME/cc-switch/config.yaml // 3. ~/.config/cc-switch/config.yaml // // The --config flag, when provided, bypasses this function entirely. func ResolvePath() (string, error) { if v := os.Getenv(EnvConfigPath); v != "" { return ExpandUser(v) } if xdg := os.Getenv("XDG_CONFIG_HOME"); xdg != "" { return filepath.Join(xdg, "cc-switch", "config.yaml"), nil } home, err := os.UserHomeDir() if err != nil { return "", fmt.Errorf("resolve home dir: %w", err) } return filepath.Join(home, ".config", "cc-switch", "config.yaml"), nil }