rename

package
v0.0.0-...-a69402d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "rename",
	Short: "重命名项目总包名",
	Long:  `默认包名为 sniper 可以按需修改`,
	Run: func(cmd *cobra.Command, args []string) {
		if rootPkg == "" {
			panic("package cannot be empty")
		}
		module := getModuleName()
		module = strings.ReplaceAll(module, ".", "\\.")

		sh := fmt.Sprintf(`grep --exclude .git -rlI '"%s/' %s | xargs sed -i '' 's#"%s/#"%s/#'`, module, goModDir, module, rootPkg)

		c1 := exec.Command("bash")
		c1.Stdin = strings.NewReader(sh)
		c1.Stdout = os.Stdout
		c1.Stderr = os.Stderr
		c1.Run()

		modPath := "go.mod"
		if len(goModDir) > 0 {
			modPath = filepath.Join(goModDir, "go.mod")
		}
		sh = fmt.Sprintf(`sed -i '' 's#module %s#module %s#' %s`, module, rootPkg, modPath)
		c2 := exec.Command("bash")
		c2.Stdin = strings.NewReader(sh)
		c2.Stdout = os.Stdout
		c2.Stderr = os.Stderr
		c2.Run()
	},
}

Cmd 项目重命名工具

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL