1
0
mirror of https://github.com/golang/go synced 2024-11-22 21:00:04 -07:00

cmd/go: emit error when listing with -f and -json

Fixes #44738
Change-Id: Ie57ddcbe87408c9644313ec2a9ea347b4d6de76b
Reviewed-on: https://go-review.googlesource.com/c/go/+/298029
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Ayan George 2021-03-02 17:44:22 -05:00 committed by Bryan C. Mills
parent 402d784b8f
commit 9f4d5c94b0
2 changed files with 24 additions and 0 deletions

View File

@ -335,6 +335,10 @@ var (
var nl = []byte{'\n'}
func runList(ctx context.Context, cmd *base.Command, args []string) {
if *listFmt != "" && *listJson == true {
base.Fatalf("go list -f cannot be used with -json")
}
load.ModResolveTests = *listTest
work.BuildInit()
out := newTrackingWriter(os.Stdout)

View File

@ -0,0 +1,20 @@
[short] skip
# list -json should generate output on stdout
go list -json ./...
stdout .
# list -f should generate output on stdout
go list -f '{{.}}' ./...
stdout .
# test passing first -json then -f
! go list -json -f '{{.}}' ./...
stderr '^go list -f cannot be used with -json$'
# test passing first -f then -json
! go list -f '{{.}}' -json ./...
stderr '^go list -f cannot be used with -json$'
-- go.mod --
module m
-- list_test.go --
package list_test