MCPcopy
hub / github.com/Ne0nd0g/merlin / GetModuleList

Function GetModuleList

pkg/modules/modules.go:192–223  ·  view source on GitHub ↗

GetModuleList generates and returns a list of all modules in Merlin's "module" directory folder. Used with tab completion

()

Source from the content-addressed store, hash-verified

190
191// GetModuleList generates and returns a list of all modules in Merlin's "module" directory folder. Used with tab completion
192func GetModuleList() []string {
193 dir, err := os.Getwd()
194 if err != nil {
195 slog.Error(err.Error())
196 return []string{}
197 }
198 ModuleDir := path.Join(filepath.ToSlash(dir), "data", "modules")
199 o := make([]string, 0)
200
201 err = filepath.Walk(ModuleDir, func(path string, f os.FileInfo, err error) error {
202 if err != nil {
203 fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", ModuleDir, err)
204 return err
205 }
206 if strings.HasSuffix(f.Name(), ".json") {
207 d := strings.SplitAfter(filepath.ToSlash(path), ModuleDir)
208 if len(d) > 0 {
209 m := d[1]
210 m = strings.TrimLeft(m, "/")
211 m = strings.TrimSuffix(m, ".json")
212 if !strings.Contains(m, "templates") {
213 o = append(o, m)
214 }
215 }
216 }
217 return nil
218 })
219 if err != nil {
220 fmt.Printf("error walking the path %q: %v\n", ModuleDir, err)
221 }
222 return o
223}

Callers 1

GetModuleListMethod · 0.92

Calls 2

ErrorMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected