-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor.go
88 lines (77 loc) · 3.14 KB
/
doctor.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package doctor
import (
"fmt"
"os/exec"
"strings"
"github.com/gosuri/uiprogress/util/strutil"
"github.com/spf13/cobra"
)
type DoctorCmd struct {
*cobra.Command
}
func NewDoctorCmd() *DoctorCmd {
c := &DoctorCmd{}
c.Command = &cobra.Command{
Use: "doctor",
Short: "Check requirement to use this cli",
Long: "Check requirement to use this cli",
}
c.Command.RunE = c.runCommand
return c
}
func (c *DoctorCmd) runCommand(cmd *cobra.Command, args []string) error {
const (
InfoColor = "\033[1;34m%s\033[0m"
NoticeColor = "\033[1;36m%s\033[0m"
WarningColor = "\033[1;33m%s\033[0m"
ErrorColor = "\033[1;31m%s\033[0m"
DebugColor = "\033[0;36m%s\033[0m"
SuccessColor = "\033[1;32m%s\033[0m"
)
protocVersion, err := exec.Command(`protoc`, "--version").Output()
if err == nil {
fmt.Printf(SuccessColor, "[v] ")
fmt.Println(fmt.Sprintf("protoc (%s)", fmt.Sprint(strings.Replace(string(protocVersion), "\n", "", -1))))
} else {
fmt.Printf(ErrorColor, "[x] ")
fmt.Println("protoc")
fmt.Printf(ErrorColor+"\n", fmt.Sprint(strutil.Resize("", 4), "protoc hasn't installed yet: https://grpc.io/docs/protoc-installation/"))
}
protocGenGoVersion, err := exec.Command(`protoc-gen-go`, "--version").Output()
if err == nil {
fmt.Printf(SuccessColor, "[v] ")
fmt.Println(fmt.Sprintf("protoc-gen-go (%s)", fmt.Sprint(strings.Replace(string(protocGenGoVersion), "\n", "", -1))))
} else {
fmt.Printf(ErrorColor, "[x] ")
fmt.Println("protoc-gen-go")
fmt.Printf(ErrorColor+"\n", fmt.Sprint(strutil.Resize("", 4), "protoc-gen-go hasn't installed yet: https://grpc.io/docs/languages/go/quickstart/"))
}
protocGenGoGrpcVersion, err := exec.Command(`protoc-gen-go-grpc`, "--version").Output()
if err == nil {
fmt.Printf(SuccessColor, "[v] ")
fmt.Println(fmt.Sprintf("protoc-gen-go-grpc (%s)", fmt.Sprint(strings.Replace(string(protocGenGoGrpcVersion), "\n", "", -1))))
} else {
fmt.Printf(ErrorColor, "[x] ")
fmt.Println("protoc-gen-go-grpc")
fmt.Printf(ErrorColor+"\n", fmt.Sprint(strutil.Resize("", 4), "protoc-gen-go-grpc hasn't installed yet: https://grpc.io/docs/languages/go/quickstart/"))
}
protocGenGrpcGatewayVersion, err := exec.Command(`protoc-gen-grpc-gateway`, "--version").Output()
if err == nil {
fmt.Printf(SuccessColor, "[v] ")
fmt.Println(fmt.Sprintf("protoc-gen-grpc-gateway (%s)", fmt.Sprint(strings.Replace(string(protocGenGrpcGatewayVersion), "\n", "", -1))))
} else {
fmt.Printf(ErrorColor, "[x] ")
fmt.Println("protoc-gen-grpc-gateway")
fmt.Printf(ErrorColor+"\n", fmt.Sprint(strutil.Resize("", 4), "protoc-gen-grpc-gateway hasn't installed yet: https://github.com/grpc-ecosystem/grpc-gateway"))
}
protocGenCddVersion, err := exec.Command(`protoc-gen-cdd`, "--version").Output()
if err == nil {
fmt.Printf(SuccessColor, "[v] ")
fmt.Println(fmt.Sprintf("protoc-gen-cdd (%s)", fmt.Sprint(strings.Replace(string(protocGenCddVersion), "\n", "", -1))))
} else {
fmt.Printf(ErrorColor, "[x] ")
fmt.Println("protoc-gen-cdd")
fmt.Printf(ErrorColor+"\n", fmt.Sprint(strutil.Resize("", 4), "protoc-gen-cdd hasn't installed yet: https://github.com/krisnasw/go-grst/tree/main/protoc-gen-cdd"))
}
return nil
}