ignr/filter.go
onyx-and-iris 70b1c373ae replace huh with promptui
- it gives more control over filtering

add --filter/-f flag, this allows configuration over a prefix vs contains filter

update the README to reflect changes
2025-06-18 03:31:34 +01:00

22 lines
571 B
Go

package main
import (
"strings"
"github.com/spf13/viper"
)
// filterFunc returns a function that filters templates based on the specified filter type.
func filterFunc(templates []string) func(input string, index int) bool {
switch viper.GetString("filter") {
case "contains":
return func(input string, index int) bool {
return strings.Contains(strings.ToLower(templates[index]), strings.ToLower(input))
}
default:
return func(input string, index int) bool {
return strings.HasPrefix(strings.ToLower(templates[index]), strings.ToLower(input))
}
}
}