Skip to content

Commit ed7e430

Browse files
danpBryan C. Mills
authored andcommitted
cmd/go: respect -mod flag in fmt
Fixes golang#27841 Change-Id: Ifcfd938aff8680cf7b44dfc09fde01d6105345a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/198257 Run-TryBot: Dan Peterson <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent decf9f6 commit ed7e430

4 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/cmd/go/alldocs.go

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

src/cmd/go/internal/base/flag.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ func AddBuildFlagsNX(flags *flag.FlagSet) {
3333
flags.BoolVar(&cfg.BuildN, "n", false, "")
3434
flags.BoolVar(&cfg.BuildX, "x", false, "")
3535
}
36+
37+
// AddLoadFlags adds the -mod build flag to the flag set.
38+
func AddLoadFlags(flags *flag.FlagSet) {
39+
flags.StringVar(&cfg.BuildMod, "mod", "", "")
40+
}

src/cmd/go/internal/fmtcmd/fmt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
func init() {
2424
base.AddBuildFlagsNX(&CmdFmt.Flag)
25+
base.AddLoadFlags(&CmdFmt.Flag)
2526
}
2627

2728
var CmdFmt = &base.Command{
@@ -38,6 +39,9 @@ For more about specifying packages, see 'go help packages'.
3839
The -n flag prints commands that would be executed.
3940
The -x flag prints commands as they are executed.
4041
42+
The -mod flag's value sets which module download mode
43+
to use: readonly or vendor. See 'go help modules' for more.
44+
4145
To run gofmt with specific options, run gofmt itself.
4246
4347
See also: go fix, go vet.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ go build
6363
go build -mod=vendor
6464
go test -mod=vendor . ./subdir
6565
go test -mod=vendor ./...
66+
go fmt -mod=vendor ./...
6667

6768
-- go.mod --
6869
module m

0 commit comments

Comments
 (0)