1 // The gorename command performs precise type-safe renaming of
2 // identifiers in Go source code.
4 // Run with -help for usage information, or view the Usage constant in
5 // package golang.org/x/tools/refactor/rename, which contains most of
8 package main // import "golang.org/x/tools/cmd/gorename"
17 "golang.org/x/tools/go/buildutil"
18 "golang.org/x/tools/refactor/rename"
22 offsetFlag = flag.String("offset", "", "file and byte offset of identifier to be renamed, e.g. 'file.go:#123'. For use by editors.")
23 fromFlag = flag.String("from", "", "identifier to be renamed; see -help for formats")
24 toFlag = flag.String("to", "", "new name for identifier")
25 helpFlag = flag.Bool("help", false, "show usage message")
29 flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)
30 flag.BoolVar(&rename.Force, "force", false, "proceed, even if conflicts were reported")
31 flag.BoolVar(&rename.Verbose, "v", false, "print verbose information")
32 flag.BoolVar(&rename.Diff, "d", false, "display diffs instead of rewriting files")
33 flag.StringVar(&rename.DiffCmd, "diffcmd", "diff", "diff command invoked when using -d")
37 log.SetPrefix("gorename: ")
40 if len(flag.Args()) > 0 {
41 log.Fatal("surplus arguments")
44 if *helpFlag || (*offsetFlag == "" && *fromFlag == "" && *toFlag == "") {
45 fmt.Println(rename.Usage)
49 if err := rename.Main(&build.Default, *offsetFlag, *fromFlag, *toFlag); err != nil {
50 if err != rename.ConflictError {