Skip to content

Commit

Permalink
fixed parsing of test flags that are prefixed with dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
integrii committed Jan 18, 2020
1 parent 2e29894 commit 3980c6b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 3980c6b

Please sign in to comment.