properly skip non-build flags for 'go list'

If the flags list included ["-o" "binary"], we would properly skip "-o",
but we wouldn't skip "binary".

Thus, 'go list' would receive "binary" as the first argument, and assume
that's the first parameter and the end of the flags.

And add a unit test case.

Fixes #82, again.
pull/92/head
Daniel Martí 4 years ago
parent 870cde9a0a
commit 98113d0124

@ -1030,7 +1030,7 @@ func filterBuildFlags(flags []string) (filtered []string) {
continue
}
// "-name value", so the next arg is part of this flag.
if i++; i < len(flags) {
if i++; buildFlag && i < len(flags) {
filtered = append(filtered, flags[i])
}
}

@ -392,6 +392,11 @@ func TestFilterBuildFlags(t *testing.T) {
[]string{"-short", "-tags", "foo", "-mod=readonly", "-json"},
[]string{"-tags", "foo", "-mod=readonly"},
},
{
"NonBinarySkipped",
[]string{"-o", "binary", "-tags", "foo"},
[]string{"-tags", "foo"},
},
}
for _, test := range tests {
test := test

Loading…
Cancel
Save