return path
}
-// parsePath parses -flag=arg expecting arg to be path to a tool (allows ./)
-func parseToolPath(flag, arg string) (path string) {
- if strings.Contains(arg, "@") {
- base.Fatalf("go: -%s=%s: need just path, not path@version", flag, arg)
- }
- if arg == "." {
- return arg
- }
- toCheck := arg
- if strings.HasPrefix(arg, "./") {
- toCheck = arg[2:]
- }
- if err := module.CheckImportPath(toCheck); err != nil {
- base.Fatalf("go: -%s=%s: invalid path: %v", flag, arg, err)
- }
-
- return arg
-}
-
// parsePathVersionOptional parses path[@version], using adj to
// describe any errors.
func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
// flagTool implements the -tool flag.
func flagTool(arg string) {
- path := parseToolPath("tool", arg)
+ path := parsePath("tool", arg)
edits = append(edits, func(f *modfile.File) {
if err := f.AddTool(path); err != nil {
base.Fatalf("go: -tool=%s: %v", arg, err)
// flagDropTool implements the -droptool flag.
func flagDropTool(arg string) {
- path := parseToolPath("droptool", arg)
+ path := parsePath("droptool", arg)
edits = append(edits, func(f *modfile.File) {
if err := f.DropTool(path); err != nil {
base.Fatalf("go: -droptool=%s: %v", arg, err)
cp go.mod.start go.mod
go mod edit -tool example.com/tool
cmpenv go.mod go.mod.edit
-go mod edit -tool ./local
-cmpenv go.mod go.mod.edit2
-go mod edit -droptool ./local
-cmpenv go.mod go.mod.edit
go mod edit -droptool example.com/tool2
cmpenv go.mod go.mod.edit
go mod edit -droptool example.com/tool
go 1.24
tool example.com/tool
--- $WORK/h/go.mod.edit2 --
-module g
-
-go 1.24
-
-tool (
- ./local
- example.com/tool
-)