---------- loading ---------------------------------------------------------- LoadAll returns all repo entries for the given kind by merging sources configured in config.yaml. The loading order follows the Python RepoConfigLoader exactly: 1. Bundled JSON embedded in the binary (lowest priority, fa
(kind entities.Kind)
| 134 | // If config.yaml has no sources or cannot be loaded, only the bundled |
| 135 | // entries are returned. |
| 136 | func LoadAll(kind entities.Kind) (map[string]RepoEntry, error) { |
| 137 | if kind == entities.KindInstruction { |
| 138 | if _, err := MigrateRepoConfigFiles(pathutil.ConfigDir()); err != nil { |
| 139 | return nil, err |
| 140 | } |
| 141 | } |
| 142 | merged := make(map[string]RepoEntry) |
| 143 | |
| 144 | // 1. Bundled defaults (lowest priority). |
| 145 | bundled, err := loadBundled(kind) |
| 146 | if err != nil { |
| 147 | return nil, fmt.Errorf("repoconfig: bundled: %w", err) |
| 148 | } |
| 149 | for k, v := range bundled { |
| 150 | merged[k] = v |
| 151 | } |
| 152 | |
| 153 | // 2. Walk every source from config.yaml in declaration order. |
| 154 | cfg, cfgErr := camconfig.Load("") |
| 155 | if cfgErr == nil { |
| 156 | repoKey := repoConfigKey(kind) |
| 157 | if src, ok := cfg.Repositories[repoKey]; ok { |
| 158 | for _, s := range src.Sources { |
| 159 | switch s.Type { |
| 160 | case "local": |
| 161 | if s.Path == "" { |
| 162 | continue |
| 163 | } |
| 164 | local, err := LoadLocalSource(s.Path) |
| 165 | if err != nil || local == nil { |
| 166 | continue |
| 167 | } |
| 168 | // Local sources override everything (same as Python's |
| 169 | // repos.update(loaded)). |
| 170 | for k, v := range local { |
| 171 | merged[k] = v |
| 172 | } |
| 173 | |
| 174 | case "remote": |
| 175 | if s.URL == "" { |
| 176 | continue |
| 177 | } |
| 178 | remote, err := loadRemoteWithCache(s.URL, kind, cfg.Cache) |
| 179 | if err != nil { |
| 180 | // Non-fatal: remote may be unavailable. |
| 181 | continue |
| 182 | } |
| 183 | // Remote entries only fill gaps — don't override keys |
| 184 | // already set by a local source (same as Python's |
| 185 | // "if key not in repos: repos[key] = value"). |
| 186 | for k, v := range remote { |
| 187 | if _, exists := merged[k]; !exists { |
| 188 | merged[k] = v |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
no test coverage detected