From: Ayan George Date: Tue, 2 Mar 2021 22:44:22 +0000 (-0500) Subject: cmd/go: emit error when listing with -f and -json X-Git-Tag: go1.17beta1~979 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9f4d5c94b0cafc4d888b7f02e4ff12c2ff39eedc;p=gostls13.git 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 Trust: Jay Conrod --- diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index bb48d2d2ea..1e1c6495bf 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -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) diff --git a/src/cmd/go/testdata/script/list_json_with_f.txt b/src/cmd/go/testdata/script/list_json_with_f.txt new file mode 100644 index 0000000000..2011a6e808 --- /dev/null +++ b/src/cmd/go/testdata/script/list_json_with_f.txt @@ -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