Skip to content

Commit f1c8e2c

Browse files
committed
cmd/go: enable -x in go mod download
Lack of logging hinders debugging. Like many other go commands, let's allow users to inspect what is going on underneath. Example: $ GO111MODULE=on GOPROXY=direct GOPATH=`mktemp -d` go mod download -x golang.org/x/tools/gopls@latest mkdir -p /var/folders/bw/6r6k9d113sv1_vvzk_1kfxbm001py5/T/tmp.ykhTiXaS/pkg/mod/cache/vcs # git3 https://go.googlesource.com/tools ... Update #35849 Change-Id: I5577e683ae3c0145b11822df255b210ad9f60c87 Reviewed-on: https://go-review.googlesource.com/c/go/+/208558 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent b11d02e commit f1c8e2c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/cmd/go/alldocs.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/modcmd/download.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
var cmdDownload = &base.Command{
22-
UsageLine: "go mod download [-json] [modules]",
22+
UsageLine: "go mod download [-x] [-json] [modules]",
2323
Short: "download modules to local cache",
2424
Long: `
2525
Download downloads the named modules, which can be module patterns selecting
@@ -47,6 +47,8 @@ corresponding to this Go struct:
4747
GoModSum string // checksum for go.mod (as in go.sum)
4848
}
4949
50+
The -x flag causes download to print the commands download executes.
51+
5052
See 'go help modules' for more about module queries.
5153
`,
5254
}
@@ -56,6 +58,8 @@ var downloadJSON = cmdDownload.Flag.Bool("json", false, "")
5658
func init() {
5759
cmdDownload.Run = runDownload // break init cycle
5860

61+
// TODO(jayconrod): https://golang.org/issue/35849 Apply -x to other 'go mod' commands.
62+
cmdDownload.Flag.BoolVar(&cfg.BuildX, "x", false, "")
5963
work.AddModCommonFlags(cmdDownload)
6064
}
6165

src/cmd/go/testdata/script/mod_download.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ env GOPROXY=$GOPROXY/quiet
44
# download with version should print nothing
55
go mod download rsc.io/[email protected]
66
! stdout .
7+
! stderr .
78

89
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
910
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
@@ -106,5 +107,11 @@ rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
106107
go mod download rsc.io/[email protected]
107108
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
108109

110+
# download -x with version should print
111+
# the underlying commands such as contacting GOPROXY.
112+
go mod download -x rsc.io/[email protected]
113+
! stdout .
114+
stderr 'get '$GOPROXY
115+
109116
-- go.mod --
110117
module m

0 commit comments

Comments
 (0)