MCPcopy Create free account
hub / github.com/diillson/chatcli / LoadConfig

Function LoadConfig

pkg/registry/config.go:76–118  ·  view source on GitHub ↗

LoadConfig reads the registries config from disk. If the file doesn't exist, it creates it with defaults.

()

Source from the content-addressed store, hash-verified

74// LoadConfig reads the registries config from disk.
75// If the file doesn't exist, it creates it with defaults.
76func 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.
121func SaveConfig(cfg RegistriesConfig) error {

Callers 2

NewSkillHandlerFunction · 0.92
SetRegistryEnabledMethod · 0.92

Calls 5

ConfigPathFunction · 0.85
SaveConfigFunction · 0.85
mergeDefaultRegistriesFunction · 0.85
applyEnvOverridesFunction · 0.85
DefaultConfigFunction · 0.70

Tested by

no test coverage detected