From d308149381315c7508c720f7f3ce9f6fd35ba737 Mon Sep 17 00:00:00 2001 From: Ryan SU Date: Sat, 8 Jul 2023 22:08:24 +0800 Subject: [PATCH 1/2] feat: mcms env info --- tools/goctl/info/env/env.go | 3 + tools/goctl/info/env/mcms.go | 64 ++++++++++++++++++++++ tools/goctl/internal/flags/default_en.json | 2 +- tools/goctl/internal/flags/zh.json | 2 +- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 tools/goctl/info/env/mcms.go diff --git a/tools/goctl/info/env/env.go b/tools/goctl/info/env/env.go index 3828d8b5d7b0..68aba880a2b9 100644 --- a/tools/goctl/info/env/env.go +++ b/tools/goctl/info/env/env.go @@ -46,6 +46,9 @@ func ShowEnv(_ *cobra.Command, _ []string) error { captchaEnvInfo() case "fms": fmsEnvInfo() + case "mcms": + mcmsEmailEnvInfo() + mcmsSmsEnvInfo() } return nil diff --git a/tools/goctl/info/env/mcms.go b/tools/goctl/info/env/mcms.go new file mode 100644 index 000000000000..403a5306e0c2 --- /dev/null +++ b/tools/goctl/info/env/mcms.go @@ -0,0 +1,64 @@ +package env + +import ( + "github.com/gookit/color" + "github.com/jedib0t/go-pretty/v6/table" + "os" +) + +func mcmsEmailEnvInfo() string { + color.Green.Println("MCMS") + color.Green.Println("EMAIL") + envInfo = table.NewWriter() + envInfo.SetOutputMirror(os.Stdout) + if lang { + envInfo.AppendHeader(table.Row{"环境变量名称", "环境变量介绍"}) + envInfo.AppendRows([]table.Row{ + {"EMAIL_AUTH_TYPE", "电子邮箱的认证类型,支持plain和CRAMMD5"}, + {"EMAIL_ADDR", "电子邮箱地址"}, + {"EMAIL_PASSWORD", "电子邮箱密码"}, + {"EMAIL_HOST_NAME", "电子邮箱的服务器地址"}, + {"EMAIL_PORT", "电子邮箱的服务器端口"}, + {"EMAIL_IDENTIFY", "电子邮箱的身份信息,用于CRAMMD5"}, + {"EMAIL_SECRET", "电子邮箱的密钥信息,用于CRAMMD5"}, + {"EMAIL_TLS", "是否启用TLS"}, + }) + } else { + envInfo.AppendHeader(table.Row{"Key", "Introduction"}) + envInfo.AppendRows([]table.Row{ + {"EMAIL_AUTH_TYPE", "Authentication type for the email, supports plain and CRAMMD5"}, + {"EMAIL_ADDR", "Email address"}, + {"EMAIL_PASSWORD", "Email password"}, + {"EMAIL_HOST_NAME", "Server address for the email"}, + {"EMAIL_PORT", "Server port for the email"}, + {"EMAIL_IDENTIFY", "Identity information for the email, used for CRAMMD5"}, + {"EMAIL_SECRET", "Secret information for the email, used for CRAMMD5"}, + {"EMAIL_TLS", "Whether to enable TLS"}, + }) + } + return envInfo.Render() +} + +func mcmsSmsEnvInfo() string { + color.Green.Println("SMS") + envInfo = table.NewWriter() + envInfo.SetOutputMirror(os.Stdout) + if lang { + envInfo.AppendHeader(table.Row{"环境变量名称", "环境变量介绍"}) + envInfo.AppendRows([]table.Row{ + {"SMS_SECRET_ID", "短信服务密钥ID"}, + {"SMS_SECRET_KEY", "短信服务密钥"}, + {"SMS_PROVIDER", "短信服务提供商"}, + {"SMS_REGION", "短信服务提供区域"}, + }) + } else { + envInfo.AppendHeader(table.Row{"Key", "Introduction"}) + envInfo.AppendRows([]table.Row{ + {"SMS_SECRET_ID", "Secret ID for the SMS service"}, + {"SMS_SECRET_KEY", "Secret key for the SMS service"}, + {"SMS_PROVIDER", "Provider for the SMS service"}, + {"SMS_REGION", "Region for the SMS service"}, + }) + } + return envInfo.Render() +} diff --git a/tools/goctl/internal/flags/default_en.json b/tools/goctl/internal/flags/default_en.json index 8bd63ca0c45d..7d8e13ddaaad 100644 --- a/tools/goctl/internal/flags/default_en.json +++ b/tools/goctl/internal/flags/default_en.json @@ -336,7 +336,7 @@ "short": "View additional information, such as environment variables and project port usage.", "env": { "short": "View environment variables.", - "service_name": "Service name, support: core, fms" + "service_name": "Service name, support: core, fms, mcms" }, "port": { "short": "View port usage." diff --git a/tools/goctl/internal/flags/zh.json b/tools/goctl/internal/flags/zh.json index 9bd602eb3072..4b7d050f89c6 100644 --- a/tools/goctl/internal/flags/zh.json +++ b/tools/goctl/internal/flags/zh.json @@ -336,7 +336,7 @@ "short": "查看额外信息,如环境变量和项目端口使用情况", "env": { "short": "查看环境变量", - "service_name": "服务名称,支持: core, fms" + "service_name": "服务名称,支持: core, fms, mcms" }, "port": { "short": "查看端口使用情况" From f5488ff230ce9fefa1902c893ac97d594e24df8b Mon Sep 17 00:00:00 2001 From: Ryan SU Date: Sun, 9 Jul 2023 12:30:18 +0800 Subject: [PATCH 2/2] feat: service list in info cmd --- tools/goctl/info/cmd.go | 1 + tools/goctl/info/env/env.go | 6 +++++ tools/goctl/info/env/service_list.go | 30 ++++++++++++++++++++++ tools/goctl/internal/flags/default_en.json | 3 ++- tools/goctl/internal/flags/zh.json | 3 ++- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tools/goctl/info/env/service_list.go diff --git a/tools/goctl/info/cmd.go b/tools/goctl/info/cmd.go index 501e905a3232..2d63b0ca7898 100644 --- a/tools/goctl/info/cmd.go +++ b/tools/goctl/info/cmd.go @@ -36,6 +36,7 @@ func init() { ) envCmdFlags.StringVarPWithDefaultValue(&env.ServiceName, "service_name", "s", "core") + envCmdFlags.BoolVarP(&env.ShowList, "list", "l") Cmd.AddCommand(EnvCmd) Cmd.AddCommand(PortCmd) diff --git a/tools/goctl/info/env/env.go b/tools/goctl/info/env/env.go index 68aba880a2b9..385792bef719 100644 --- a/tools/goctl/info/env/env.go +++ b/tools/goctl/info/env/env.go @@ -21,10 +21,16 @@ import ( var ( ServiceName string + ShowList bool ) // ShowEnv is used to show the environment variable usages. func ShowEnv(_ *cobra.Command, _ []string) error { + if ShowList { + getServiceList() + return nil + } + if lang { color.Green.Println("Simple Admin的环境变量") color.Red.Println("注意: 环境变量的优先级大于配置文件") diff --git a/tools/goctl/info/env/service_list.go b/tools/goctl/info/env/service_list.go new file mode 100644 index 000000000000..dfc6ec59c419 --- /dev/null +++ b/tools/goctl/info/env/service_list.go @@ -0,0 +1,30 @@ +package env + +import ( + "github.com/gookit/color" + "github.com/jedib0t/go-pretty/v6/table" + "os" +) + +// getServiceList returns the service list +func getServiceList() string { + color.Green.Println("Service ") + envInfo = table.NewWriter() + envInfo.SetOutputMirror(os.Stdout) + if lang { + envInfo.AppendHeader(table.Row{"服务名称", "服务介绍"}) + envInfo.AppendRows([]table.Row{ + {"core", "核心服务"}, + {"fms", "文件服务"}, + {"mcms", "消息中心服务"}, + }) + } else { + envInfo.AppendHeader(table.Row{"Service name", "Introduction"}) + envInfo.AppendRows([]table.Row{ + {"core", "Core Service"}, + {"fms", "File Management Service"}, + {"mcms", "Message Center Service"}, + }) + } + return envInfo.Render() +} diff --git a/tools/goctl/internal/flags/default_en.json b/tools/goctl/internal/flags/default_en.json index 7d8e13ddaaad..4176967a1cba 100644 --- a/tools/goctl/internal/flags/default_en.json +++ b/tools/goctl/internal/flags/default_en.json @@ -336,7 +336,8 @@ "short": "View additional information, such as environment variables and project port usage.", "env": { "short": "View environment variables.", - "service_name": "Service name, support: core, fms, mcms" + "service_name": "Service name, support: core, fms, mcms", + "list": "Show the list of supported services" }, "port": { "short": "View port usage." diff --git a/tools/goctl/internal/flags/zh.json b/tools/goctl/internal/flags/zh.json index 4b7d050f89c6..b63c96778461 100644 --- a/tools/goctl/internal/flags/zh.json +++ b/tools/goctl/internal/flags/zh.json @@ -336,7 +336,8 @@ "short": "查看额外信息,如环境变量和项目端口使用情况", "env": { "short": "查看环境变量", - "service_name": "服务名称,支持: core, fms, mcms" + "service_name": "服务名称,支持: core, fms, mcms", + "list": "列出支持的服务" }, "port": { "short": "查看端口使用情况"