]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: respect -mod flag in fmt
authorDan Peterson <dpiddy@gmail.com>
Tue, 1 Oct 2019 16:53:42 +0000 (13:53 -0300)
committerBryan C. Mills <bcmills@google.com>
Tue, 8 Oct 2019 19:19:46 +0000 (19:19 +0000)
Fixes #27841

Change-Id: Ifcfd938aff8680cf7b44dfc09fde01d6105345a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/198257
Run-TryBot: Dan Peterson <dpiddy@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/alldocs.go
src/cmd/go/internal/base/flag.go
src/cmd/go/internal/fmtcmd/fmt.go
src/cmd/go/testdata/script/mod_vendor.txt

index 115eec4167f5763700701ec84a6b208ae8b65b1b..bf00e1f4c935cd4216dc5f3cc62e644f8da4de8c 100644 (file)
 // The -n flag prints commands that would be executed.
 // The -x flag prints commands as they are executed.
 //
+// The -mod flag's value sets which module download mode
+// to use: readonly or vendor. See 'go help modules' for more.
+//
 // To run gofmt with specific options, run gofmt itself.
 //
 // See also: go fix, go vet.
index 5e03e6405884d27eb5fce6b2623da9187b1760c6..6727196816b56c620d8cee65aff4eec60d438658 100644 (file)
@@ -33,3 +33,8 @@ func AddBuildFlagsNX(flags *flag.FlagSet) {
        flags.BoolVar(&cfg.BuildN, "n", false, "")
        flags.BoolVar(&cfg.BuildX, "x", false, "")
 }
+
+// AddLoadFlags adds the -mod build flag to the flag set.
+func AddLoadFlags(flags *flag.FlagSet) {
+       flags.StringVar(&cfg.BuildMod, "mod", "", "")
+}
index 8e4ef37281662500463f54fb1f80ec1f35f5f001..e898d73d60bc0b8f97c6e20193569464b827aba1 100644 (file)
@@ -22,6 +22,7 @@ import (
 
 func init() {
        base.AddBuildFlagsNX(&CmdFmt.Flag)
+       base.AddLoadFlags(&CmdFmt.Flag)
 }
 
 var CmdFmt = &base.Command{
@@ -38,6 +39,9 @@ For more about specifying packages, see 'go help packages'.
 The -n flag prints commands that would be executed.
 The -x flag prints commands as they are executed.
 
+The -mod flag's value sets which module download mode
+to use: readonly or vendor. See 'go help modules' for more.
+
 To run gofmt with specific options, run gofmt itself.
 
 See also: go fix, go vet.
index 5d872c3c80ef73956146ca95a67c22850f254e79..74ef2d827ec55c1ba9f794a614dc7c7d2a024ccf 100644 (file)
@@ -63,6 +63,7 @@ go build
 go build -mod=vendor
 go test -mod=vendor . ./subdir
 go test -mod=vendor ./...
+go fmt -mod=vendor ./...
 
 -- go.mod --
 module m