chore: Add command desc & color commands (#2013)

* Add link & Color sub-commands

* Color sub-commands for unix-like OS

* Remove useless code

* Remove redundant dependency
This commit is contained in:
anqiansong
2022-06-21 20:21:38 +08:00
committed by GitHub
parent b44e8f5c75
commit 93b3f5030f
8 changed files with 117 additions and 16 deletions

View File

@@ -1,10 +1,12 @@
package cmd
import (
_ "embed"
"fmt"
"os"
"runtime"
"strings"
"text/template"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
@@ -30,11 +32,18 @@ const (
assign = "="
)
var rootCmd = &cobra.Command{
Use: "goctl",
Short: "A cli tool to generate go-zero code",
Long: "A cli tool to generate api, zrpc, model code",
}
var (
//go:embed usage.tpl
usageTpl string
rootCmd = &cobra.Command{
Use: "goctl",
Short: "A cli tool to generate go-zero code",
Long: "A cli tool to generate api, zrpc, model code\n\n" +
"GitHub: https://github.com/zeromicro/go-zero\n" +
"Site: https://go-zero.dev",
}
)
// Execute executes the given command
func Execute() {
@@ -96,9 +105,18 @@ func isBuiltin(name string) bool {
}
func init() {
cobra.AddTemplateFuncs(template.FuncMap{
"blue": blue,
"green": green,
"rpadx": rpadx,
"rainbow": rainbow,
})
rootCmd.Version = fmt.Sprintf(
"%s %s/%s", version.BuildVersion,
runtime.GOOS, runtime.GOARCH)
rootCmd.SetUsageTemplate(usageTpl)
rootCmd.AddCommand(api.Cmd)
rootCmd.AddCommand(bug.Cmd)
rootCmd.AddCommand(docker.Cmd)