Rename IgnoreFieldsRegex -> IgnoreFields.
This commit is contained in:
@@ -121,7 +121,7 @@ func buildNode(k *Kong, v reflect.Value, typ NodeType, seenFlags map[string]bool
|
||||
|
||||
MAIN:
|
||||
for _, field := range fields {
|
||||
for _, r := range k.ignoreFieldsRegex {
|
||||
for _, r := range k.ignoreFields {
|
||||
if r.MatchString(v.Type().Name() + "." + field.field.Name) {
|
||||
continue MAIN
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ type Kong struct {
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
|
||||
bindings bindings
|
||||
loader ConfigurationLoader
|
||||
resolvers []Resolver
|
||||
registry *Registry
|
||||
ignoreFieldsRegex []*regexp.Regexp
|
||||
bindings bindings
|
||||
loader ConfigurationLoader
|
||||
resolvers []Resolver
|
||||
registry *Registry
|
||||
ignoreFields []*regexp.Regexp
|
||||
|
||||
noDefaultHelp bool
|
||||
usageOnError usageOnError
|
||||
@@ -75,14 +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,
|
||||
ignoreFieldsRegex: make([]*regexp.Regexp, 0),
|
||||
Exit: os.Exit,
|
||||
Stdout: os.Stdout,
|
||||
Stderr: os.Stderr,
|
||||
registry: NewRegistry().RegisterDefaults(),
|
||||
vars: Vars{},
|
||||
bindings: bindings{},
|
||||
helpFormatter: DefaultHelpValueFormatter,
|
||||
ignoreFields: make([]*regexp.Regexp, 0),
|
||||
}
|
||||
|
||||
options = append(options, Bind(k))
|
||||
|
||||
+2
-2
@@ -1321,7 +1321,7 @@ type testIgnoreFields struct {
|
||||
func TestIgnoreRegex(t *testing.T) {
|
||||
cli := testIgnoreFields{}
|
||||
|
||||
k, err := kong.New(&cli, kong.IgnoreFieldsRegex(`.*\.XXX_.+`))
|
||||
k, err := kong.New(&cli, kong.IgnoreFields(`.*\.XXX_.+`))
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = k.Parse([]string{"foo", "sub"})
|
||||
@@ -1343,7 +1343,7 @@ func TestIgnoreRegex(t *testing.T) {
|
||||
func TestIgnoreRegexEmpty(t *testing.T) {
|
||||
cli := testIgnoreFields{}
|
||||
|
||||
_, err := kong.New(&cli, kong.IgnoreFieldsRegex(""))
|
||||
_, err := kong.New(&cli, kong.IgnoreFields(""))
|
||||
require.Error(t, err)
|
||||
require.Contains(t, "regex input cannot be empty", err.Error())
|
||||
}
|
||||
|
||||
+3
-3
@@ -304,13 +304,13 @@ func Resolvers(resolvers ...Resolver) Option {
|
||||
})
|
||||
}
|
||||
|
||||
// IgnoreFieldsRegex will cause kong.New() to skip field names that match any
|
||||
// IgnoreFields will cause kong.New() to skip field names that match any
|
||||
// of the provided regex patterns. This is useful if you are not able to add a
|
||||
// kong="-" struct tag to a struct/element before the call to New.
|
||||
//
|
||||
// Example: When referencing protoc generated structs, you will likely want to
|
||||
// ignore/skip XXX_* fields.
|
||||
func IgnoreFieldsRegex(regexes ...string) Option {
|
||||
func IgnoreFields(regexes ...string) Option {
|
||||
return OptionFunc(func(k *Kong) error {
|
||||
for _, r := range regexes {
|
||||
if r == "" {
|
||||
@@ -322,7 +322,7 @@ func IgnoreFieldsRegex(regexes ...string) Option {
|
||||
return errors.Wrap(err, "unable to compile regex")
|
||||
}
|
||||
|
||||
k.ignoreFieldsRegex = append(k.ignoreFieldsRegex, re)
|
||||
k.ignoreFields = append(k.ignoreFields, re)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user