Skip to content

Commit b76103c

Browse files
committed
cmd/go: output missing GoDebug entries
The `go help mod edit` command references the GoDebug struct, but `go mod edit -json` was not displaying them when appropriate. Fixes #75105 Change-Id: Iec987882941e01b0cf4d4fe31dda9e7a6e2dde87 Reviewed-on: https://go-review.googlesource.com/c/go/+/706757 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
1 parent 47a63a3 commit b76103c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/cmd/go/internal/modcmd/edit.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,9 @@ func flagDropIgnore(arg string) {
584584
// fileJSON is the -json output data structure.
585585
type fileJSON struct {
586586
Module editModuleJSON
587-
Go string `json:",omitempty"`
588-
Toolchain string `json:",omitempty"`
587+
Go string `json:",omitempty"`
588+
Toolchain string `json:",omitempty"`
589+
GoDebug []debugJSON `json:",omitempty"`
589590
Require []requireJSON
590591
Exclude []module.Version
591592
Replace []replaceJSON
@@ -599,6 +600,11 @@ type editModuleJSON struct {
599600
Deprecated string `json:",omitempty"`
600601
}
601602

603+
type debugJSON struct {
604+
Key string
605+
Value string
606+
}
607+
602608
type requireJSON struct {
603609
Path string
604610
Version string `json:",omitempty"`
@@ -657,6 +663,9 @@ func editPrintJSON(modFile *modfile.File) {
657663
for _, i := range modFile.Ignore {
658664
f.Ignore = append(f.Ignore, ignoreJSON{i.Path})
659665
}
666+
for _, d := range modFile.Godebug {
667+
f.GoDebug = append(f.GoDebug, debugJSON{d.Key, d.Value})
668+
}
660669
data, err := json.MarshalIndent(&f, "", "\t")
661670
if err != nil {
662671
base.Fatalf("go: internal error: %v", err)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
env GO111MODULE=on
2+
3+
go mod edit -godebug 'http2debug=2'
4+
cmp go.mod go.mod.edit.want1
5+
6+
go mod edit -json
7+
cmp stdout go.mod.edit.want2
8+
-- go.mod --
9+
module foo
10+
11+
go 1.25.0
12+
-- go.mod.edit.want1 --
13+
module foo
14+
15+
go 1.25.0
16+
17+
godebug http2debug=2
18+
-- go.mod.edit.want2 --
19+
{
20+
"Module": {
21+
"Path": "foo"
22+
},
23+
"Go": "1.25.0",
24+
"GoDebug": [
25+
{
26+
"Key": "http2debug",
27+
"Value": "2"
28+
}
29+
],
30+
"Require": null,
31+
"Exclude": null,
32+
"Replace": null,
33+
"Retract": null,
34+
"Tool": null,
35+
"Ignore": null
36+
}

0 commit comments

Comments
 (0)