MCPcopy Create free account
hub / github.com/driangle/taskmd / loadConfigForValidation

Function loadConfigForValidation

apps/cli/internal/cli/validate.go:226–264  ·  view source on GitHub ↗

loadConfigForValidation extracts config data from viper for validation. Returns nil if no config file was loaded.

()

Source from the content-addressed store, hash-verified

224// loadConfigForValidation extracts config data from viper for validation.
225// Returns nil if no config file was loaded.
226func loadConfigForValidation() *validator.ConfigData {
227 configPath := viper.ConfigFileUsed()
228 if configPath == "" {
229 return nil
230 }
231
232 // Only include keys actually present in the config file, not pflag-bound defaults
233 allSettings := viper.AllSettings()
234 topKeys := make([]string, 0, len(allSettings))
235 for k := range allSettings {
236 if viper.InConfig(k) {
237 topKeys = append(topKeys, k)
238 }
239 }
240 sort.Strings(topKeys)
241
242 config := &validator.ConfigData{
243 TopKeys: topKeys,
244 ConfigPath: configPath,
245 Workflow: viper.GetString("workflow"),
246 }
247
248 raw := viper.Get("scopes")
249 if raw != nil {
250 if scopeMap, ok := raw.(map[string]any); ok {
251 config.Scopes = parseScopeEntries(scopeMap)
252 }
253 }
254
255 if viper.InConfig("id") {
256 config.ID = parseIDConfig(viper.Get("id"))
257 }
258
259 if viper.InConfig("phases") {
260 config.Phases = parsePhasesConfig(viper.Get("phases"))
261 }
262
263 return config
264}
265
266// parseIDConfig converts raw viper id data into a typed IDConfig.
267// Returns nil if raw is nil or not a map.

Callers 1

validateConfigFunction · 0.85

Calls 3

parseScopeEntriesFunction · 0.85
parseIDConfigFunction · 0.85
parsePhasesConfigFunction · 0.85

Tested by

no test coverage detected