LoadConfig reads the registries config from disk. If the file doesn't exist, it creates it with defaults.
()
| 74 | // LoadConfig reads the registries config from disk. |
| 75 | // If the file doesn't exist, it creates it with defaults. |
| 76 | func LoadConfig() (RegistriesConfig, error) { |
| 77 | configPath := filepath.Clean(ConfigPath()) |
| 78 | |
| 79 | data, err := os.ReadFile(configPath) // #nosec G304 -- path from ConfigPath (user home dir) |
| 80 | if err != nil { |
| 81 | if os.IsNotExist(err) { |
| 82 | cfg := DefaultConfig() |
| 83 | if saveErr := SaveConfig(cfg); saveErr != nil { |
| 84 | // Non-fatal: use defaults even if save fails |
| 85 | return cfg, nil |
| 86 | } |
| 87 | return cfg, nil |
| 88 | } |
| 89 | return RegistriesConfig{}, err |
| 90 | } |
| 91 | |
| 92 | var cfg RegistriesConfig |
| 93 | if err := yaml.Unmarshal(data, &cfg); err != nil { |
| 94 | return RegistriesConfig{}, err |
| 95 | } |
| 96 | |
| 97 | // Apply defaults for missing fields |
| 98 | if cfg.InstallDir == "" { |
| 99 | homeDir, _ := os.UserHomeDir() |
| 100 | cfg.InstallDir = filepath.Join(homeDir, ".chatcli", "skills") |
| 101 | } |
| 102 | if cfg.MaxConcurrent <= 0 { |
| 103 | cfg.MaxConcurrent = 3 |
| 104 | } |
| 105 | if cfg.SearchCacheSize <= 0 { |
| 106 | cfg.SearchCacheSize = 50 |
| 107 | } |
| 108 | |
| 109 | // Merge default registries: add any built-in registries that are missing |
| 110 | // from the user's config. This ensures new registries (like skills.sh) |
| 111 | // appear automatically after an upgrade without requiring manual edits. |
| 112 | cfg = mergeDefaultRegistries(cfg) |
| 113 | |
| 114 | // Apply environment variable overrides |
| 115 | cfg = applyEnvOverrides(cfg) |
| 116 | |
| 117 | return cfg, nil |
| 118 | } |
| 119 | |
| 120 | // SaveConfig writes the registries config to disk. |
| 121 | func SaveConfig(cfg RegistriesConfig) error { |
no test coverage detected