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:
|
MAIN:
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
for _, r := range k.ignoreFieldsRegex {
|
for _, r := range k.ignoreFields {
|
||||||
if r.MatchString(v.Type().Name() + "." + field.field.Name) {
|
if r.MatchString(v.Type().Name() + "." + field.field.Name) {
|
||||||
continue MAIN
|
continue MAIN
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ type Kong struct {
|
|||||||
loader ConfigurationLoader
|
loader ConfigurationLoader
|
||||||
resolvers []Resolver
|
resolvers []Resolver
|
||||||
registry *Registry
|
registry *Registry
|
||||||
ignoreFieldsRegex []*regexp.Regexp
|
ignoreFields []*regexp.Regexp
|
||||||
|
|
||||||
noDefaultHelp bool
|
noDefaultHelp bool
|
||||||
usageOnError usageOnError
|
usageOnError usageOnError
|
||||||
@@ -82,7 +82,7 @@ func New(grammar interface{}, options ...Option) (*Kong, error) {
|
|||||||
vars: Vars{},
|
vars: Vars{},
|
||||||
bindings: bindings{},
|
bindings: bindings{},
|
||||||
helpFormatter: DefaultHelpValueFormatter,
|
helpFormatter: DefaultHelpValueFormatter,
|
||||||
ignoreFieldsRegex: make([]*regexp.Regexp, 0),
|
ignoreFields: make([]*regexp.Regexp, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
options = append(options, Bind(k))
|
options = append(options, Bind(k))
|
||||||
|
|||||||
+2
-2
@@ -1321,7 +1321,7 @@ type testIgnoreFields struct {
|
|||||||
func TestIgnoreRegex(t *testing.T) {
|
func TestIgnoreRegex(t *testing.T) {
|
||||||
cli := testIgnoreFields{}
|
cli := testIgnoreFields{}
|
||||||
|
|
||||||
k, err := kong.New(&cli, kong.IgnoreFieldsRegex(`.*\.XXX_.+`))
|
k, err := kong.New(&cli, kong.IgnoreFields(`.*\.XXX_.+`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = k.Parse([]string{"foo", "sub"})
|
_, err = k.Parse([]string{"foo", "sub"})
|
||||||
@@ -1343,7 +1343,7 @@ func TestIgnoreRegex(t *testing.T) {
|
|||||||
func TestIgnoreRegexEmpty(t *testing.T) {
|
func TestIgnoreRegexEmpty(t *testing.T) {
|
||||||
cli := testIgnoreFields{}
|
cli := testIgnoreFields{}
|
||||||
|
|
||||||
_, err := kong.New(&cli, kong.IgnoreFieldsRegex(""))
|
_, err := kong.New(&cli, kong.IgnoreFields(""))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Contains(t, "regex input cannot be empty", err.Error())
|
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
|
// 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.
|
// kong="-" struct tag to a struct/element before the call to New.
|
||||||
//
|
//
|
||||||
// Example: When referencing protoc generated structs, you will likely want to
|
// Example: When referencing protoc generated structs, you will likely want to
|
||||||
// ignore/skip XXX_* fields.
|
// ignore/skip XXX_* fields.
|
||||||
func IgnoreFieldsRegex(regexes ...string) Option {
|
func IgnoreFields(regexes ...string) Option {
|
||||||
return OptionFunc(func(k *Kong) error {
|
return OptionFunc(func(k *Kong) error {
|
||||||
for _, r := range regexes {
|
for _, r := range regexes {
|
||||||
if r == "" {
|
if r == "" {
|
||||||
@@ -322,7 +322,7 @@ func IgnoreFieldsRegex(regexes ...string) Option {
|
|||||||
return errors.Wrap(err, "unable to compile regex")
|
return errors.Wrap(err, "unable to compile regex")
|
||||||
}
|
}
|
||||||
|
|
||||||
k.ignoreFieldsRegex = append(k.ignoreFieldsRegex, re)
|
k.ignoreFields = append(k.ignoreFields, re)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user