1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00

cmd/go: respect -mod flag in fmt

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>
This commit is contained in:
Dan Peterson 2019-10-01 13:53:42 -03:00 committed by Bryan C. Mills
parent decf9f6fef
commit ed7e43085e
4 changed files with 13 additions and 0 deletions

View File

@ -435,6 +435,9 @@
// 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.

View 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", "", "")
}

View 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.

View 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