Add ability to ignore fields that match given regex pattern(s) (#199)

This commit is contained in:
Daniel Selans
2021-08-27 22:41:08 -07:00
committed by GitHub
parent dd904ce961
commit 07faa2e0d0
4 changed files with 111 additions and 11 deletions
+9
View File
@@ -24,6 +24,7 @@ func build(k *Kong, ast interface{}) (app *Application, err error) {
for _, flag := range extraFlags {
seenFlags[flag.Name] = true
}
node, err := buildNode(k, iv, ApplicationNode, seenFlags)
if err != nil {
return nil, err
@@ -112,7 +113,15 @@ func buildNode(k *Kong, v reflect.Value, typ NodeType, seenFlags map[string]bool
if err != nil {
return nil, err
}
MAIN:
for _, field := range fields {
for _, r := range k.ignoreFieldsRegex {
if r.MatchString(v.Type().Name() + "." + field.field.Name) {
continue MAIN
}
}
ft := field.field
fv := field.value