Skip to content

Commit

Permalink
change command name
Browse files Browse the repository at this point in the history
  • Loading branch information
zhufuyi committed Jan 6, 2024
1 parent 47abf59 commit 1ed443a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions assets/install-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions assets/install-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-gin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-rpc-tmpl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions cmd/sponge/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,9 +31,9 @@ Examples:
return err
}

// installing dependent plug-ins
_, lackNames := checkInstallTools()
installTools(lackNames)
// installing dependency plugins
_, lackNames := checkInstallPlugins()
installPlugins(lackNames)

return nil
},
Expand Down
82 changes: 55 additions & 27 deletions cmd/sponge/commands/tools.go → cmd/sponge/commands/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/spf13/cobra"
)

var toolNames = []string{
var pluginNames = []string{
"go",
"protoc",
"protoc-gen-go",
Expand All @@ -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",
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/sponge/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ docs: https://go-sponge.com`,
cmd.AddCommand(
InitCommand(),
UpgradeCommand(),
ToolsCommand(),
PluginsCommand(),
GenWebCommand(),
GenMicroCommand(),
generate.ConfigCommand(),
Expand Down

0 comments on commit 1ed443a

Please sign in to comment.