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
+14 -11
View File
@@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
)
@@ -48,10 +49,11 @@ type Kong struct {
Stdout io.Writer
Stderr io.Writer
bindings bindings
loader ConfigurationLoader
resolvers []Resolver
registry *Registry
bindings bindings
loader ConfigurationLoader
resolvers []Resolver
registry *Registry
ignoreFieldsRegex []*regexp.Regexp
noDefaultHelp bool
usageOnError usageOnError
@@ -73,13 +75,14 @@ type Kong struct {
// See the README (https://github.com/alecthomas/kong) for usage instructions.
func New(grammar interface{}, options ...Option) (*Kong, error) {
k := &Kong{
Exit: os.Exit,
Stdout: os.Stdout,
Stderr: os.Stderr,
registry: NewRegistry().RegisterDefaults(),
vars: Vars{},
bindings: bindings{},
helpFormatter: DefaultHelpValueFormatter,
Exit: os.Exit,
Stdout: os.Stdout,
Stderr: os.Stderr,
registry: NewRegistry().RegisterDefaults(),
vars: Vars{},
bindings: bindings{},
helpFormatter: DefaultHelpValueFormatter,
ignoreFieldsRegex: make([]*regexp.Regexp, 0),
}
options = append(options, Bind(k))