|
6 | 6 | "fmt" |
7 | 7 | "os" |
8 | 8 | "path/filepath" |
| 9 | + "slices" |
9 | 10 | "sort" |
10 | 11 | "strings" |
11 | 12 |
|
|
28 | 29 | catsYaml = "categories.yaml" |
29 | 30 | ) |
30 | 31 |
|
31 | | -type BuildCmd struct { |
32 | | - InPath string `name:"path" short:"p" help:"Path to read rules" default:"rules"` |
33 | | - OutPath string `name:"out" short:"o" help:"Optional path to write files; default curdir"` |
34 | | - Version string `name:"vers" short:"v" help:"Optional semantic version override"` |
35 | | -} |
36 | | - |
37 | | -func RunBuild(inPath, outPath, vers string) error { |
| 32 | +func RunBuild(inPath, outPath, vers string, exclude []string) error { |
38 | 33 |
|
39 | 34 | if outPath == "" { |
40 | 35 | var err error |
@@ -64,7 +59,7 @@ func RunBuild(inPath, outPath, vers string) error { |
64 | 59 | } |
65 | 60 | } |
66 | 61 |
|
67 | | - if err := _build(vers, inPath, outPath, packageName); err != nil { |
| 62 | + if err := _build(vers, inPath, outPath, packageName, exclude); err != nil { |
68 | 63 | return err |
69 | 64 | } |
70 | 65 |
|
@@ -200,7 +195,17 @@ func processRules(path string, ruleDupes, termDupes dupesT, tags tagsT) (*parser |
200 | 195 | return allRules, nil |
201 | 196 | } |
202 | 197 |
|
203 | | -func _build(vers, inPath, outPath, packageName string) error { |
| 198 | +func containsAny[T comparable](a, b []T) bool { |
| 199 | + for _, v := range b { |
| 200 | + log.Debug().Any("v", v).Any("a", a).Msg("containsAny") |
| 201 | + if slices.Contains(a, v) { |
| 202 | + return true |
| 203 | + } |
| 204 | + } |
| 205 | + return false |
| 206 | +} |
| 207 | + |
| 208 | +func _build(vers, inPath, outPath, packageName string, exclude []string) error { |
204 | 209 |
|
205 | 210 | var ( |
206 | 211 | allRules = make(map[string]parser.ParseRuleT) |
@@ -253,6 +258,10 @@ func _build(vers, inPath, outPath, packageName string) error { |
253 | 258 | } |
254 | 259 |
|
255 | 260 | for _, rule := range r.Rules { |
| 261 | + if containsAny(rule.Cre.Tags, exclude) { |
| 262 | + log.Info().Str("id", rule.Cre.Id).Msg("Skipping rule due to exclude tag match") |
| 263 | + continue |
| 264 | + } |
256 | 265 | allRules[rule.Cre.Id] = rule |
257 | 266 | } |
258 | 267 |
|
@@ -284,20 +293,6 @@ func _build(vers, inPath, outPath, packageName string) error { |
284 | 293 | return nil |
285 | 294 | } |
286 | 295 |
|
287 | | -func unmarshal(data []byte) (*parser.RulesT, error) { |
288 | | - |
289 | | - var ( |
290 | | - rules *parser.RulesT |
291 | | - err error |
292 | | - ) |
293 | | - |
294 | | - if rules, err = parser.Unmarshal(data); err != nil { |
295 | | - return nil, err |
296 | | - } |
297 | | - |
298 | | - return rules, nil |
299 | | -} |
300 | | - |
301 | 296 | func compile(rules *parser.RulesT) error { |
302 | 297 |
|
303 | 298 | var ( |
|
0 commit comments