MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / ValidateKeyBindings

Function ValidateKeyBindings

internal/config/config.go:294–323  ·  view source on GitHub ↗

ValidateKeyBindings checks if all key specifications are valid.

(kb KeyBindings)

Source from the content-addressed store, hash-verified

292
293// ValidateKeyBindings checks if all key specifications are valid.
294func ValidateKeyBindings(kb KeyBindings) error {
295 bindings := keyBindingsToMap(kb)
296 defaultMap := keyBindingsToMap(DefaultKeyBindings())
297
298 seen := make(map[string]string)
299
300 for name, spec := range bindings {
301 if spec == "" {
302 continue
303 }
304
305 key, r, mod, err := keys.Parse(spec)
306 if err != nil {
307 return fmt.Errorf("invalid key binding %s: %w", name, err)
308 }
309
310 if keys.IsReserved(key, r, mod) && spec != defaultMap[name] {
311 return fmt.Errorf("key binding %s uses reserved key %s", name, spec)
312 }
313
314 id := keys.CanonicalID(key, r, mod)
315 if other, ok := seen[id]; ok {
316 return fmt.Errorf("key binding %s duplicates %s", name, other)
317 }
318
319 seen[id] = name
320 }
321
322 return nil
323}
324
325// NewConfig creates a new Config instance populated with values from environment variables.
326//

Callers 3

TestValidateKeyBindingsFunction · 0.85
ValidateMethod · 0.85

Calls 5

ParseFunction · 0.92
IsReservedFunction · 0.92
CanonicalIDFunction · 0.92
keyBindingsToMapFunction · 0.85
DefaultKeyBindingsFunction · 0.85

Tested by 1

TestValidateKeyBindingsFunction · 0.68