Debian Codegraph @

cmd/gomvpkg/main.go

raw symbols SCIP
1 // Copyright 2015 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 gomvpkg command moves go packages, updating import declarations.
6 // See the -help message or Usage constant for details.
7 package mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/
8
9 import (
10 "flagscip-go gomod github.com/golang/go/src go1.25.0 flag/"
11 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
12 "go/buildscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/"
13 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
14
15 "golang.org/x/tools/go/buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/"
16 "golang.org/x/tools/refactor/renamescip-go gomod golang.org/x/tools . `golang.org/x/tools/refactor/rename`/"
17 )
18
19 var (
20 fromFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/fromFlag. = flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Stringscip-go gomod github.com/golang/go/src go1.25.0 flag/String().("from", "", "Import path of package to be moved")
21 toFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/toFlag. = flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Stringscip-go gomod github.com/golang/go/src go1.25.0 flag/String().("to", "", "Destination import path for package")
22 vcsMvCmdFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/vcsMvCmdFlag. = flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Stringscip-go gomod github.com/golang/go/src go1.25.0 flag/String().("vcs_mv_cmd", "", `A template for the version control system's "move directory" command, e.g. "git mv {{.Src}} {{.Dst}}"`)
23 helpFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/helpFlag. = flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Boolscip-go gomod github.com/golang/go/src go1.25.0 flag/Bool().("help", false, "show usage message")
24 )
25
26 func initscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/init().() {
27 flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Varscip-go gomod github.com/golang/go/src go1.25.0 flag/Var().((*buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/.TagsFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/TagsFlag#)(&buildscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/.Defaultscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/Default..BuildTagsscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/Context#BuildTags.), "tags", buildutilscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/.TagsFlagDocscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/buildutil`/TagsFlagDoc.)
28 }
29
30 const Usagescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/Usage. = `gomvpkg: moves a package, updating import declarations
31
32 Usage:
33
34 gomvpkg -from <path> -to <path> [-vcs_mv_cmd <template>]
35
36 Flags:
37
38 -from specifies the import path of the package to be moved
39
40 -to specifies the destination import path
41
42 -vcs_mv_cmd specifies a shell command to inform the version control system of a
43 directory move. The argument is a template using the syntax of the
44 text/template package. It has two fields: Src and Dst, the absolute
45 paths of the directories.
46
47 For example: "git mv {{.Src}} {{.Dst}}"
48
49 gomvpkg determines the set of packages that might be affected, including all
50 packages importing the 'from' package and any of its subpackages. It will move
51 the 'from' package and all its subpackages to the destination path and update all
52 imports of those packages to point to its new import path.
53
54 gomvpkg rejects moves in which a package already exists at the destination import
55 path, or in which a directory already exists at the location the package would be
56 moved to.
57
58 gomvpkg will not always be able to rename imports when a package's name is changed.
59 Import statements may want further cleanup.
60
61 gomvpkg's behavior is not defined if any of the packages to be moved are
62 imported using dot imports.
63
64 Examples:
65
66 % gomvpkg -from myproject/foo -to myproject/bar
67
68 Move the package with import path "myproject/foo" to the new path
69 "myproject/bar".
70
71 % gomvpkg -from myproject/foo -to myproject/bar -vcs_mv_cmd "git mv {{.Src}} {{.Dst}}"
72
73 Move the package with import path "myproject/foo" to the new path
74 "myproject/bar" using "git mv" to execute the directory move.
75 `
76
77 func mainscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/main().() {
78 flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Parsescip-go gomod github.com/golang/go/src go1.25.0 flag/Parse().()
79
80 if len(flagscip-go gomod github.com/golang/go/src go1.25.0 flag/.Argsscip-go gomod github.com/golang/go/src go1.25.0 flag/Args().()) > 0 {
81 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintln().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., "gomvpkg: surplus arguments.")
82 osscip-go gomod github.com/golang/go/src go1.25.0 os/.Exitscip-go gomod github.com/golang/go/src go1.25.0 os/Exit().(1)
83 }
84
85 if *helpFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/helpFlag. || *fromFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/fromFlag. == "" || *toFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/toFlag. == "" {
86 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Printscip-go gomod github.com/golang/go/src go1.25.0 fmt/Print().(Usagescip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/Usage.)
87 return
88 }
89
90 if err := renamescip-go gomod golang.org/x/tools . `golang.org/x/tools/refactor/rename`/.Movescip-go gomod golang.org/x/tools . `golang.org/x/tools/refactor/rename`/Move().(&buildscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/.Defaultscip-go gomod github.com/golang/go/src go1.25.0 `go/build`/Default., *fromFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/fromFlag., *toFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/toFlag., *vcsMvCmdFlagscip-go gomod golang.org/x/tools . `golang.org/x/tools/cmd/gomvpkg`/vcsMvCmdFlag.); err != nil {
91 fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Fprintf().(osscip-go gomod github.com/golang/go/src go1.25.0 os/.Stderrscip-go gomod github.com/golang/go/src go1.25.0 os/Stderr., "gomvpkg: %s.\n", err)
92 osscip-go gomod github.com/golang/go/src go1.25.0 os/.Exitscip-go gomod github.com/golang/go/src go1.25.0 os/Exit().(1)
93 }
94 }