From 98113d012413361efbbcc61859e99bd4bd692db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 12 Aug 2020 14:05:08 +0200 Subject: [PATCH] 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. --- main.go | 2 +- main_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c3d2cb7..a7e0f43 100644 --- a/main.go +++ b/main.go @@ -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]) } } diff --git a/main_test.go b/main_test.go index 59a3bce..815e6a3 100644 --- a/main_test.go +++ b/main_test.go @@ -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