Add filter flag
This commit is contained in:
@@ -12,4 +12,5 @@ var (
|
||||
LogLevel = flag.String("loglevel", "INFO", "Set log level: ERROR, WARNING, INFO, DEBUG, TRACE")
|
||||
Cookfile = flag.String("cook", "**/cook.yml", "Path to cook config files, can be globbed")
|
||||
ParallelFiles = flag.Int("P", 100, "Number of files to process in parallel")
|
||||
Filter = flag.String("filter", "", "Filter commands before running them")
|
||||
)
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"modify/logger"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/bmatcuk/doublestar/v4"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -206,3 +207,16 @@ func CountGlobsBeforeDedup(commands []ModifyCommand) int {
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func FilterCommands(commands []ModifyCommand, filter string) []ModifyCommand {
|
||||
filteredCommands := []ModifyCommand{}
|
||||
filters := strings.Split(filter, ",")
|
||||
for _, cmd := range commands {
|
||||
for _, filter := range filters {
|
||||
if strings.Contains(cmd.Name, filter) {
|
||||
filteredCommands = append(filteredCommands, cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredCommands
|
||||
}
|
Reference in New Issue
Block a user