Commit f1c8e2c1 authored by Hana (Hyang-Ah) Kim's avatar Hana (Hyang-Ah) Kim Committed by Hyang-Ah Hana Kim

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 <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent b11d02ef
...@@ -1010,7 +1010,7 @@ ...@@ -1010,7 +1010,7 @@
// //
// Usage: // Usage:
// //
// go mod download [-json] [modules] // go mod download [-x] [-json] [modules]
// //
// Download downloads the named modules, which can be module patterns selecting // Download downloads the named modules, which can be module patterns selecting
// dependencies of the main module or module queries of the form path@version. // dependencies of the main module or module queries of the form path@version.
...@@ -1037,6 +1037,8 @@ ...@@ -1037,6 +1037,8 @@
// GoModSum string // checksum for go.mod (as in go.sum) // GoModSum string // checksum for go.mod (as in go.sum)
// } // }
// //
// The -x flag causes download to print the commands download executes.
//
// See 'go help modules' for more about module queries. // See 'go help modules' for more about module queries.
// //
// //
......
...@@ -19,7 +19,7 @@ import ( ...@@ -19,7 +19,7 @@ import (
) )
var cmdDownload = &base.Command{ var cmdDownload = &base.Command{
UsageLine: "go mod download [-json] [modules]", UsageLine: "go mod download [-x] [-json] [modules]",
Short: "download modules to local cache", Short: "download modules to local cache",
Long: ` Long: `
Download downloads the named modules, which can be module patterns selecting Download downloads the named modules, which can be module patterns selecting
...@@ -47,6 +47,8 @@ corresponding to this Go struct: ...@@ -47,6 +47,8 @@ corresponding to this Go struct:
GoModSum string // checksum for go.mod (as in go.sum) GoModSum string // checksum for go.mod (as in go.sum)
} }
The -x flag causes download to print the commands download executes.
See 'go help modules' for more about module queries. See 'go help modules' for more about module queries.
`, `,
} }
...@@ -56,6 +58,8 @@ var downloadJSON = cmdDownload.Flag.Bool("json", false, "") ...@@ -56,6 +58,8 @@ var downloadJSON = cmdDownload.Flag.Bool("json", false, "")
func init() { func init() {
cmdDownload.Run = runDownload // break init cycle cmdDownload.Run = runDownload // break init cycle
// TODO(jayconrod): https://golang.org/issue/35849 Apply -x to other 'go mod' commands.
cmdDownload.Flag.BoolVar(&cfg.BuildX, "x", false, "")
work.AddModCommonFlags(cmdDownload) work.AddModCommonFlags(cmdDownload)
} }
......
...@@ -4,6 +4,7 @@ env GOPROXY=$GOPROXY/quiet ...@@ -4,6 +4,7 @@ env GOPROXY=$GOPROXY/quiet
# download with version should print nothing # download with version should print nothing
go mod download rsc.io/quote@v1.5.0 go mod download rsc.io/quote@v1.5.0
! stdout . ! stdout .
! stderr .
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod 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 ...@@ -106,5 +107,11 @@ rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
go mod download rsc.io/quote@v1.2.1 go mod download rsc.io/quote@v1.2.1
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.2.1.zip
# download -x with version should print
# the underlying commands such as contacting GOPROXY.
go mod download -x rsc.io/quote@v1.0.0
! stdout .
stderr 'get '$GOPROXY
-- go.mod -- -- go.mod --
module m module m
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment