From 3980c6b5cda386231cd174a6e8e3f843d5bd3eb4 Mon Sep 17 00:00:00 2001 From: Eric Greer Date: Sat, 18 Jan 2020 12:14:37 -0800 Subject: [PATCH] fixed parsing of test flags that are prefixed with dashes --- parser.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/parser.go b/parser.go index c3aed54..dffcf24 100644 --- a/parser.go +++ b/parser.go @@ -78,16 +78,15 @@ func (p *Parser) ParseArgs(args []string) error { // incoming args should be in the order supplied by the user and should not // include the invoked binary, which is normally the first thing in os.Args. func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []string { + // DebugMode = true + // defer func() { + // DebugMode = false + // }() + var argsNotUsed []string var skipNext bool for _, a := range args { - // skip args that start with 'test.' because they are injected with go test - if strings.HasPrefix(a, "test.") { - debugPrint("skipping test. prefixed arg:", a) - continue - } - // if the final argument (--) is seen, then we stop checking because all // further values are trailing arguments. if determineArgType(a) == argIsFinal { @@ -104,6 +103,14 @@ func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []stri // keys from parsedValues. arg := parseFlagToName(a) + // skip args that start with 'test.' because they are injected with go test + debugPrint("flagsNotParsed: checking arg:", arg) + if strings.HasPrefix(a, "test.") { + debugPrint("skipping test. prefixed arg named:", arg) + continue + } + debugPrint("flagsNotParsed: flag is unused:", arg) + // indicates that we found this arg used in one of the parsed values. Used // to indicate which values should be added to argsNotUsed. var foundArgUsed bool