mirror of
https://github.com/onyx-and-iris/ignr.git
synced 2025-07-27 06:11:48 +00:00
- 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
22 lines
571 B
Go
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))
|
|
}
|
|
}
|
|
}
|