mirror of
https://github.com/mustbeperfect/definitive-opensource.git
synced 2026-04-19 12:54:17 +02:00
Moved cli and web directory into app dir
This commit is contained in:
42
apps/cli/new/select_category.go
Normal file
42
apps/cli/new/select_category.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"definitive-opencore/data"
|
||||
)
|
||||
|
||||
func selectCategory(scanner *bufio.Scanner) (string, error) {
|
||||
subs, err := data.LoadSubcategories()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for {
|
||||
fmt.Print("Search category: ")
|
||||
scanner.Scan()
|
||||
query := strings.ToLower(scanner.Text())
|
||||
|
||||
filtered := []string{}
|
||||
for _, s := range subs {
|
||||
if strings.Contains(strings.ToLower(s.Name), query) {
|
||||
filtered = append(filtered, fmt.Sprintf("%s (%s)", s.Name, s.ID))
|
||||
}
|
||||
}
|
||||
|
||||
for i, f := range filtered {
|
||||
fmt.Printf("%d) %s\n", i+1, f)
|
||||
}
|
||||
|
||||
fmt.Print("Select category number: ")
|
||||
var idx int
|
||||
fmt.Scanln(&idx)
|
||||
if idx > 0 && idx <= len(filtered) {
|
||||
return subs[idx-1].ID, nil
|
||||
}
|
||||
|
||||
fmt.Println("Invalid selection, try again")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user