MCPcopy
hub / github.com/mkchoi212/fac / LoadSettings

Function LoadSettings

binding/binding.go:62–96  ·  view source on GitHub ↗

LoadSettings looks for a user specified key-binding settings file - `$HOME/.fac.yml` and returns a map representation of the file It also looks for errors, and ambiguities within the file and notifies the user of them

()

Source from the content-addressed store, hash-verified

60// and returns a map representation of the file
61// It also looks for errors, and ambiguities within the file and notifies the user of them
62func LoadSettings() (b Binding, err error) {
63 warnings := []string{}
64
65 b, ok := parseSettings()
66 if ok != nil {
67 warnings = append(warnings, ok.Error())
68 }
69
70 verificationWarnings, fatals := b.verify()
71 warnings = append(warnings, verificationWarnings...)
72
73 if len(warnings) != 0 {
74 fmt.Println(color.Yellow(color.Regular, "⚠️ %d infraction(s) detected in .fac.yml", len(warnings)))
75 for _, msg := range warnings {
76 fmt.Println(color.Yellow(color.Regular, "%s", msg))
77 }
78 fmt.Println()
79 }
80
81 if len(fatals) != 0 {
82 var errorMsg bytes.Buffer
83 errorMsg.WriteString(color.Red(color.Regular, "🚫 %d unrecoverable error(s) detected in .fac.yml", len(fatals)))
84 for _, msg := range fatals {
85 errorMsg.WriteString(color.Red(color.Regular, "\n%s", msg))
86 }
87 return nil, errors.New(errorMsg.String())
88 }
89
90 if len(warnings) != 0 {
91 time.Sleep(time.Duration(2) * time.Second)
92 }
93
94 b.consolidate()
95 return
96}
97
98// parseSettings looks for `$HOME/.fac.yml` and parses it into a `Binding` value
99// If the file does not exist, it returns the `defaultBinding`

Callers 1

TestLoadSettingsFunction · 0.85

Calls 4

parseSettingsFunction · 0.85
verifyMethod · 0.80
StringMethod · 0.80
consolidateMethod · 0.80

Tested by 1

TestLoadSettingsFunction · 0.68