]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: emit error when listing with -f and -json
authorAyan George <ayan@ayan.net>
Tue, 2 Mar 2021 22:44:22 +0000 (17:44 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 25 Mar 2021 13:57:08 +0000 (13:57 +0000)
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>

src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/list_json_with_f.txt [new file with mode: 0644]

index bb48d2d2eada8cd4a5d3edf12107cab5e99cf04b..1e1c6495bfe7f75a550e25a23d78c9dfe4663ef7 100644 (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)
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 (file)
index 0000000..2011a6e
--- /dev/null
@@ -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