aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/list/list.go4
-rw-r--r--src/cmd/go/testdata/script/list_json_with_f.txt20
2 files changed, 24 insertions, 0 deletions
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