MCPcopy
hub / github.com/moonD4rk/HackBrowserData / parseCategories

Function parseCategories

cmd/hack-browser-data/dump.go:67–94  ·  view source on GitHub ↗

parseCategories converts a comma-separated string into a Category slice. "all" returns all categories.

(s string)

Source from the content-addressed store, hash-verified

65// parseCategories converts a comma-separated string into a Category slice.
66// "all" returns all categories.
67func parseCategories(s string) ([]types.Category, error) {
68 s = strings.TrimSpace(s)
69 if strings.EqualFold(s, "all") {
70 return types.AllCategories, nil
71 }
72
73 categoryMap := make(map[string]types.Category, len(types.AllCategories))
74 for _, c := range types.AllCategories {
75 categoryMap[c.String()] = c
76 }
77
78 var categories []types.Category
79 for _, name := range strings.Split(s, ",") {
80 name = strings.TrimSpace(strings.ToLower(name))
81 if name == "" {
82 continue
83 }
84 c, ok := categoryMap[name]
85 if !ok {
86 return nil, fmt.Errorf("unknown category: %q, available: all|%s", name, categoryNames())
87 }
88 categories = append(categories, c)
89 }
90 if len(categories) == 0 {
91 return nil, fmt.Errorf("no categories specified")
92 }
93 return categories, nil
94}
95
96func categoryNames() string {
97 names := make([]string, len(types.AllCategories))

Callers 3

archiveCmdFunction · 0.85
restoreCmdFunction · 0.85
dumpCmdFunction · 0.85

Calls 3

categoryNamesFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected