1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // The gorename command performs precise type-safe renaming of
6 // identifiers in Go source code.
8 // Run with -help for usage information, or view the Usage constant in
9 // package golang.org/x/tools/refactor/rename, which contains most of
10 // the implementation.
12 package main // import "golang.org/x/tools/cmd/gorename"
21 "golang.org/x/tools/go/buildutil"
22 "golang.org/x/tools/refactor/rename"
26 offsetFlag = flag.String("offset", "", "file and byte offset of identifier to be renamed, e.g. 'file.go:#123'. For use by editors.")
27 fromFlag = flag.String("from", "", "identifier to be renamed; see -help for formats")
28 toFlag = flag.String("to", "", "new name for identifier")
29 helpFlag = flag.Bool("help", false, "show usage message")
33 flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc)
34 flag.BoolVar(&rename.Force, "force", false, "proceed, even if conflicts were reported")
35 flag.BoolVar(&rename.Verbose, "v", false, "print verbose information")
36 flag.BoolVar(&rename.Diff, "d", false, "display diffs instead of rewriting files")
37 flag.StringVar(&rename.DiffCmd, "diffcmd", "diff", "diff command invoked when using -d")
41 log.SetPrefix("gorename: ")
44 if len(flag.Args()) > 0 {
45 log.Fatal("surplus arguments")
48 if *helpFlag || (*offsetFlag == "" && *fromFlag == "" && *toFlag == "") {
49 fmt.Println(rename.Usage)
53 if err := rename.Main(&build.Default, *offsetFlag, *fromFlag, *toFlag); err != nil {
54 if err != rename.ConflictError {