Skip to content

Commit 2f6ba0c

Browse files
committed
cmd/go/internal/modget: print a fatal error if -d=false
Between Go 1.18 and Go 1.22 go get printed a fatal error if -d was explicitly set to false. That behavior was reverted in CL 572176, when we made the -d flag a no-op, but it would make it easier to remove the -d flag in the future if we continue to print a fatal error if -d is explicitly set to false. This change brings back the fatal error for -d=false while keeping the warning printed for -d=true. For #43684 Change-Id: I38ae3a3619d408c0237ff485ddee4403b8188abd Reviewed-on: https://go-review.googlesource.com/c/go/+/591135 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]>
1 parent 4b0dd55 commit 2f6ba0c

File tree

1 file changed

+30
-3
lines changed
  • src/cmd/go/internal/modget

1 file changed

+30
-3
lines changed

src/cmd/go/internal/modget/get.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"path/filepath"
3333
"runtime"
3434
"sort"
35+
"strconv"
3536
"strings"
3637
"sync"
3738

@@ -208,7 +209,7 @@ variable for future go command invocations.
208209
}
209210

210211
var (
211-
getD = CmdGet.Flag.Bool("d", false, "")
212+
getD dFlag
212213
getF = CmdGet.Flag.Bool("f", false, "")
213214
getFix = CmdGet.Flag.Bool("fix", false, "")
214215
getM = CmdGet.Flag.Bool("m", false, "")
@@ -242,9 +243,32 @@ func (v *upgradeFlag) Set(s string) error {
242243

243244
func (v *upgradeFlag) String() string { return "" }
244245

246+
// dFlag is a custom flag.Value for the deprecated -d flag
247+
// which will be used to provide warnings or errors if -d
248+
// is provided.
249+
type dFlag struct {
250+
value bool
251+
set bool
252+
}
253+
254+
func (v *dFlag) IsBoolFlag() bool { return true }
255+
256+
func (v *dFlag) Set(s string) error {
257+
v.set = true
258+
value, err := strconv.ParseBool(s)
259+
if err != nil {
260+
err = errors.New("parse error")
261+
}
262+
v.value = value
263+
return err
264+
}
265+
266+
func (b *dFlag) String() string { return "" }
267+
245268
func init() {
246269
work.AddBuildFlags(CmdGet, work.OmitModFlag)
247270
CmdGet.Run = runGet // break init loop
271+
CmdGet.Flag.Var(&getD, "d", "")
248272
CmdGet.Flag.Var(&getU, "u", "")
249273
}
250274

@@ -255,8 +279,11 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
255279
default:
256280
base.Fatalf("go: unknown upgrade flag -u=%s", getU.rawVersion)
257281
}
258-
if *getD {
259-
fmt.Fprintf(os.Stderr, "go: -d flag is a no-op\n")
282+
if getD.set {
283+
if !getD.value {
284+
base.Fatalf("go: -d flag may not be set to false")
285+
}
286+
fmt.Fprintf(os.Stderr, "go: -d flag is deprecated. -d=true is a no-op\n")
260287
}
261288
if *getF {
262289
fmt.Fprintf(os.Stderr, "go: -f flag is a no-op\n")

0 commit comments

Comments
 (0)