@@ -66,6 +66,8 @@ The -toolchain=version flag sets the Go toolchain to use.
66
66
This flag is mainly for tools that understand Go version dependencies.
67
67
Users should prefer 'go get toolchain@version'.
68
68
69
+ The -droptoolchain flag removes the toolchain directive from the go.mod file.
70
+
69
71
The -exclude=path@version and -dropexclude=path@version flags
70
72
add and drop an exclusion for the given module path and version.
71
73
Note that -exclude=path@version is a no-op if that exclusion already exists.
@@ -95,7 +97,7 @@ for the given path.
95
97
96
98
The -godebug, -dropgodebug, -require, -droprequire, -exclude, -dropexclude,
97
99
-replace, -dropreplace, -retract, -dropretract, -tool, -droptool, -ignore,
98
- and -dropignore editing flags may be repeated, and the changes are applied
100
+ -dropignore, and -droptoolchain editing flags may be repeated, and the changes are applied
99
101
in the order given.
100
102
101
103
The -print flag prints the final go.mod in its text format instead of
@@ -169,13 +171,14 @@ See https://golang.org/ref/mod#go-mod-edit for more about 'go mod edit'.
169
171
}
170
172
171
173
var (
172
- editFmt = cmdEdit .Flag .Bool ("fmt" , false , "" )
173
- editGo = cmdEdit .Flag .String ("go" , "" , "" )
174
- editToolchain = cmdEdit .Flag .String ("toolchain" , "" , "" )
175
- editJSON = cmdEdit .Flag .Bool ("json" , false , "" )
176
- editPrint = cmdEdit .Flag .Bool ("print" , false , "" )
177
- editModule = cmdEdit .Flag .String ("module" , "" , "" )
178
- edits []func (* modfile.File ) // edits specified in flags
174
+ editFmt = cmdEdit .Flag .Bool ("fmt" , false , "" )
175
+ editGo = cmdEdit .Flag .String ("go" , "" , "" )
176
+ editToolchain = cmdEdit .Flag .String ("toolchain" , "" , "" )
177
+ editJSON = cmdEdit .Flag .Bool ("json" , false , "" )
178
+ editPrint = cmdEdit .Flag .Bool ("print" , false , "" )
179
+ editModule = cmdEdit .Flag .String ("module" , "" , "" )
180
+ editDropToolchain = cmdEdit .Flag .Bool ("droptoolchain" , false , "drop the toolchain directive" )
181
+ edits []func (* modfile.File ) // edits specified in flags
179
182
)
180
183
181
184
type flagFunc func (string )
@@ -213,6 +216,7 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
213
216
* editJSON ||
214
217
* editPrint ||
215
218
* editFmt ||
219
+ * editDropToolchain ||
216
220
len (edits ) > 0
217
221
218
222
if ! anyFlags {
@@ -223,6 +227,10 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
223
227
base .Fatalf ("go: cannot use both -json and -print" )
224
228
}
225
229
230
+ if * editToolchain != "" && * editDropToolchain {
231
+ base .Fatalf ("go: -toolchain and -droptoolchain are mutually exclusive" )
232
+ }
233
+
226
234
if len (args ) > 1 {
227
235
base .Fatalf ("go: too many arguments" )
228
236
}
@@ -278,6 +286,9 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
278
286
base .Fatalf ("go: internal error: %v" , err )
279
287
}
280
288
}
289
+ if * editDropToolchain {
290
+ modFile .DropToolchainStmt ()
291
+ }
281
292
282
293
if len (edits ) > 0 {
283
294
for _ , edit := range edits {
0 commit comments