clean up docstring, remove negated condition, remove type declaration in test
diff --git a/parser.go b/parser.go
index 4bc9441..466739b 100644
--- a/parser.go
+++ b/parser.go
@@ -24,11 +24,11 @@
// NamespaceDelimiter separates group namespaces and option long names
NamespaceDelimiter string
- //UnknownOptionsHandler is a function which, if non-nil, is called
- //when the parser encounters an option that is unmapped.
- //It takes the option name and remaining args to be parsed, and should
- //return the (modified, if necessary) args, and a non-nil error if the
- //handler fails.
+ // UnknownOptionsHandler is a function which, if non-nil, is called
+ // when the parser encounters an option that is unmapped.
+ // It takes the option name and remaining args to be parsed, and should
+ // return the (modified, if necessary) args, and a non-nil error if the
+ // handler fails.
UnknownOptionHandler func(option string, args []string) ([]string, error)
internalError error
@@ -211,8 +211,8 @@
ignoreUnknown := (p.Options & IgnoreUnknown) != None
parseErr := wrapError(err)
- if !(parseErr.Type == ErrUnknownFlag &&
- (ignoreUnknown || p.UnknownOptionHandler != nil)) {
+ if parseErr.Type != ErrUnknownFlag ||
+ (!ignoreUnknown && p.UnknownOptionHandler == nil) {
s.err = parseErr
break
}
diff --git a/parser_test.go b/parser_test.go
index 620ba33..d7756ff 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -359,11 +359,10 @@
}
func TestUnknownFlagHandler(t *testing.T) {
- type options struct {
+ var opts struct {
Flag1 string `long:"flag1"`
Flag2 string `long:"flag2"`
}
- var opts options
p := NewParser(&opts, None)
var unknownFlag1 string
var unknownFlag2 bool