GoPLS Viewer

Home|gopls/cmd/gorename/main.go
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.
4
5// The gorename command performs precise type-safe renaming of
6// identifiers in Go source code.
7//
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.
11package main // import "golang.org/x/tools/cmd/gorename"
12
13import (
14    "flag"
15    "fmt"
16    "go/build"
17    "log"
18    "os"
19
20    "golang.org/x/tools/go/buildutil"
21    "golang.org/x/tools/refactor/rename"
22)
23
24var (
25    offsetFlag = flag.String("offset""""file and byte offset of identifier to be renamed, e.g. 'file.go:#123'.  For use by editors.")
26    fromFlag   = flag.String("from""""identifier to be renamed; see -help for formats")
27    toFlag     = flag.String("to""""new name for identifier")
28    helpFlag   = flag.Bool("help"false"show usage message")
29)
30
31func init() {
32    flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags"buildutil.TagsFlagDoc)
33    flag.BoolVar(&rename.Force"force"false"proceed, even if conflicts were reported")
34    flag.BoolVar(&rename.Verbose"v"false"print verbose information")
35    flag.BoolVar(&rename.Diff"d"false"display diffs instead of rewriting files")
36    flag.StringVar(&rename.DiffCmd"diffcmd""diff""diff command invoked when using -d")
37}
38
39func main() {
40    log.SetPrefix("gorename: ")
41    log.SetFlags(0)
42    flag.Parse()
43    if len(flag.Args()) > 0 {
44        log.Fatal("surplus arguments")
45    }
46
47    if *helpFlag || (*offsetFlag == "" && *fromFlag == "" && *toFlag == "") {
48        fmt.Print(rename.Usage)
49        return
50    }
51
52    if err := rename.Main(&build.Default, *offsetFlag, *fromFlag, *toFlag); err != nil {
53        if err != rename.ConflictError {
54            log.Fatal(err)
55        }
56        os.Exit(1)
57    }
58}
59
MembersX
rename
init
main
main.err
flag
build
log
buildutil
Members
X