/
env.go
44 lines (40 loc) · 1.12 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package command
import (
"fmt"
"github.com/JoeZhao1/go-start/framework/cobra"
"github.com/JoeZhao1/go-start/framework/contract"
"github.com/JoeZhao1/go-start/framework/util"
)
// initEnvCommand 获取env相关的命令
func initEnvCommand() *cobra.Command {
envCommand.AddCommand(envListCommand)
return envCommand
}
// envCommand 获取当前的App环境
var envCommand = &cobra.Command{
Use: "env",
Short: "获取当前的App环境",
Run: func(c *cobra.Command, args []string) {
// 获取env环境
container := c.GetContainer()
envService := container.MustMake(contract.EnvKey).(contract.Env)
// 打印环境
fmt.Println("environment:", envService.AppEnv())
},
}
// envListCommand 获取所有的App环境变量
var envListCommand = &cobra.Command{
Use: "list",
Short: "获取所有的环境变量",
Run: func(c *cobra.Command, args []string) {
// 获取env环境
container := c.GetContainer()
envService := container.MustMake(contract.EnvKey).(contract.Env)
envs := envService.All()
outs := [][]string{}
for k, v := range envs {
outs = append(outs, []string{k, v})
}
util.PrettyPrint(outs)
},
}