From 1ed443a3c2742a21476ae249fd151e96224e8541 Mon Sep 17 00:00:00 2001 From: zhuyasen Date: Sat, 6 Jan 2024 16:55:48 +0800 Subject: [PATCH] change command name --- Makefile | 2 +- assets/install-cn.md | 8 +- assets/install-en.md | 8 +- cmd/protoc-gen-go-gin/README.md | 2 +- cmd/protoc-gen-go-rpc-tmpl/README.md | 2 +- cmd/sponge/commands/init.go | 8 +- cmd/sponge/commands/{tools.go => plugins.go} | 82 +++++++++++++------- cmd/sponge/commands/root.go | 2 +- 8 files changed, 71 insertions(+), 43 deletions(-) rename cmd/sponge/commands/{tools.go => plugins.go} (64%) diff --git a/Makefile b/Makefile index 3f76035d..a51938a1 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/ | grep -v /api/) # delete the templates code start .PHONY: install -# installation of dependent tools +# installation of dependent plugins install: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest diff --git a/assets/install-cn.md b/assets/install-cn.md index c17a62f1..1459c577 100644 --- a/assets/install-cn.md +++ b/assets/install-cn.md @@ -64,8 +64,8 @@ go install github.com/zhufuyi/sponge/cmd/sponge@latest # 初始化sponge,自动安装sponge依赖插件 sponge init -# 查看插件是否都安装成功,如果发现有插件没有安装成功,执行命令重试 sponge tools --install -sponge tools +# 查看插件是否都安装成功,如果发现有插件没有安装成功,执行命令重试 sponge plugins --install +sponge plugins # 查看sponge版本 sponge -v @@ -150,8 +150,8 @@ go install github.com/zhufuyi/sponge/cmd/sponge@latest # 初始化sponge,自动安装sponge依赖插件 sponge init -# 查看插件是否都安装成功,如果发现有插件没有安装成功,执行命令重试 sponge tools --install -sponge tools +# 查看插件是否都安装成功,如果发现有插件没有安装成功,执行命令重试 sponge plugins --install +sponge plugins # 查看sponge版本 sponge -v diff --git a/assets/install-en.md b/assets/install-en.md index 3b1f0130..d6a12be5 100644 --- a/assets/install-en.md +++ b/assets/install-en.md @@ -62,8 +62,8 @@ go install github.com/zhufuyi/sponge/cmd/sponge@latest # Initialize Sponge, automatically install Sponge's dependency plugins sponge init -# Check if all plugins have been successfully installed. If any plugins fail to install, retry with the command: sponge tools --install -sponge tools +# Check if all plugins have been successfully installed. If any plugins fail to install, retry with the command: sponge plugins --install +sponge plugins # Check Sponge version sponge -v @@ -148,8 +148,8 @@ go install github.com/zhufuyi/sponge/cmd/sponge@latest # Initialize Sponge, automatically install Sponge's dependency plugins sponge init -# Check if all plugins have been successfully installed. If any plugins fail to install, retry with the command: sponge tools --install -sponge tools +# Check if all plugins have been successfully installed. If any plugins fail to install, retry with the command: sponge plugins --install +sponge plugins # Check Sponge version sponge -v diff --git a/cmd/protoc-gen-go-gin/README.md b/cmd/protoc-gen-go-gin/README.md index 77638fcc..ea1ffd75 100644 --- a/cmd/protoc-gen-go-gin/README.md +++ b/cmd/protoc-gen-go-gin/README.md @@ -6,7 +6,7 @@ According to protobuf to generate gin registration route codes, you can use thei ### Installation -#### Installation of dependency tools +#### Installation of dependency plugins ```bash # install protoc in linux diff --git a/cmd/protoc-gen-go-rpc-tmpl/README.md b/cmd/protoc-gen-go-rpc-tmpl/README.md index 968ce5fc..4c2604d6 100644 --- a/cmd/protoc-gen-go-rpc-tmpl/README.md +++ b/cmd/protoc-gen-go-rpc-tmpl/README.md @@ -6,7 +6,7 @@ According to protobuf to generate rpc service template codes and rpc error code ### Installation -#### Installation of dependency tools +#### Installation of dependency plugins ```bash # install protoc in linux diff --git a/cmd/sponge/commands/init.go b/cmd/sponge/commands/init.go index 554aa585..d64e2e6b 100644 --- a/cmd/sponge/commands/init.go +++ b/cmd/sponge/commands/init.go @@ -16,7 +16,7 @@ func InitCommand() *cobra.Command { Long: `initialize sponge. Examples: - # run init, download code and install tools. + # run init, download code and install plugins. sponge init `, SilenceErrors: true, @@ -31,9 +31,9 @@ Examples: return err } - // installing dependent plug-ins - _, lackNames := checkInstallTools() - installTools(lackNames) + // installing dependency plugins + _, lackNames := checkInstallPlugins() + installPlugins(lackNames) return nil }, diff --git a/cmd/sponge/commands/tools.go b/cmd/sponge/commands/plugins.go similarity index 64% rename from cmd/sponge/commands/tools.go rename to cmd/sponge/commands/plugins.go index bd9d72b2..fb5b2afa 100644 --- a/cmd/sponge/commands/tools.go +++ b/cmd/sponge/commands/plugins.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/cobra" ) -var toolNames = []string{ +var pluginNames = []string{ "go", "protoc", "protoc-gen-go", @@ -29,7 +29,7 @@ var toolNames = []string{ "go-callvis", } -var installToolCommands = map[string]string{ +var installPluginCommands = map[string]string{ "go": "go: please install manually yourself, download url is https://go.dev/dl/ or https://golang.google.cn/dl/", "protoc": "protoc: please install manually yourself, download url is https://github.com/protocolbuffers/protobuf/releases/tag/v3.20.3", "protoc-gen-go": "google.golang.org/protobuf/cmd/protoc-gen-go@latest", @@ -51,43 +51,49 @@ const ( warnSymbol = "⚠ " ) -// ToolsCommand tools management -func ToolsCommand() *cobra.Command { +// PluginsCommand plugins management +func PluginsCommand() *cobra.Command { var installFlag bool + var skipPluginName string cmd := &cobra.Command{ - Use: "tools", - Short: "Managing sponge dependency tools", - Long: `managing sponge dependency tools. + Use: "plugins", + Short: "Managing sponge dependency plugins", + Long: `managing sponge dependency plugins. Examples: - # show all dependencies tools. - sponge tools + # show all dependency plugins. + sponge plugins - # install all dependencies tools. - sponge tools --install + # install all dependency plugins. + sponge plugins --install + + # skip installing dependency plugins, multiple plugin names separated by commas + sponge plugins --install --skip=go-callvis `, SilenceErrors: true, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - installedNames, lackNames := checkInstallTools() + installedNames, lackNames := checkInstallPlugins() + lackNames = filterLackNames(lackNames, skipPluginName) if installFlag { - installTools(lackNames) + installPlugins(lackNames) } else { - showDependencyTools(installedNames, lackNames) + showDependencyPlugins(installedNames, lackNames) } return nil }, } - cmd.Flags().BoolVarP(&installFlag, "install", "i", false, "install dependent tools") + cmd.Flags().BoolVarP(&installFlag, "install", "i", false, "install dependency plugins") + cmd.Flags().StringVarP(&skipPluginName, "skip", "s", "", "skip installing dependency plugins") return cmd } -func checkInstallTools() ([]string, []string) { +func checkInstallPlugins() ([]string, []string) { var installedNames, lackNames = []string{}, []string{} - for _, name := range toolNames { + for _, name := range pluginNames { _, err := gobash.Exec("which", name) if err != nil { lackNames = append(lackNames, name) @@ -105,35 +111,35 @@ func checkInstallTools() ([]string, []string) { return installedNames, lackNames } -func showDependencyTools(installedNames []string, lackNames []string) { +func showDependencyPlugins(installedNames []string, lackNames []string) { var content string if len(installedNames) > 0 { - content = "Installed dependency tools:\n" + content = "Installed dependency plugins:\n" for _, name := range installedNames { content += " " + isntalledSymbol + " " + name + "\n" } } if len(lackNames) > 0 { - content += "\nUninstalled dependency tools:\n" + content += "\nUninstalled dependency plugins:\n" for _, name := range lackNames { content += " " + lackSymbol + " " + name + "\n" } - content += "\nInstalling dependency tools using the command: sponge tools --install\n" + content += "\nInstalling dependency plugins using the command: sponge plugins --install\n" } else { - content += "\nAll dependent tools installed.\n" + content += "\nAll dependency plugins installed.\n" } fmt.Println(content) } -func installTools(lackNames []string) { +func installPlugins(lackNames []string) { if len(lackNames) == 0 { - fmt.Printf("\n All dependent tools installed.\n\n") + fmt.Printf("\n All dependency plugins installed.\n\n") return } - fmt.Printf("install a total of %d dependent tools, need to wait a little time.\n\n", len(lackNames)) + fmt.Printf("install a total of %d dependency plugins, need to wait a little time.\n\n", len(lackNames)) var wg = &sync.WaitGroup{} var manuallyNames []string @@ -147,7 +153,7 @@ func installTools(lackNames []string) { go func(name string) { defer wg.Done() ctx, _ := context.WithTimeout(context.Background(), time.Minute*3) //nolint - pkgAddr, ok := installToolCommands[name] + pkgAddr, ok := installPluginCommands[name] if !ok { return } @@ -167,7 +173,7 @@ func installTools(lackNames []string) { wg.Wait() for _, name := range manuallyNames { - fmt.Println(warnSymbol + " " + installToolCommands[name]) + fmt.Println(warnSymbol + " " + installPluginCommands[name]) } fmt.Println() } @@ -181,3 +187,25 @@ func adaptInternalCommand(name string, pkgAddr string) string { return pkgAddr } + +func filterLackNames(lackNames []string, skipPluginName string) []string { + if skipPluginName == "" { + return lackNames + } + skipPluginNames := strings.Split(skipPluginName, ",") + + names := []string{} + for _, name := range lackNames { + isMatch := false + for _, pluginName := range skipPluginNames { + if name == pluginName { + isMatch = true + continue + } + } + if !isMatch { + names = append(names, name) + } + } + return names +} diff --git a/cmd/sponge/commands/root.go b/cmd/sponge/commands/root.go index 18cb6279..216f9009 100644 --- a/cmd/sponge/commands/root.go +++ b/cmd/sponge/commands/root.go @@ -31,7 +31,7 @@ docs: https://go-sponge.com`, cmd.AddCommand( InitCommand(), UpgradeCommand(), - ToolsCommand(), + PluginsCommand(), GenWebCommand(), GenMicroCommand(), generate.ConfigCommand(),