-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheckCommand.go
70 lines (57 loc) · 1.7 KB
/
checkCommand.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
package main
import (
"fmt"
"os"
"runtime"
"github.com/mkideal/cli"
"github.com/olekukonko/tablewriter"
)
type check struct {
cli.Helper
}
var checkCommand = &cli.Command{
Name: "check",
Desc: "check compatibility and needed binaries",
Argv: func() interface{} { return new(check) },
Fn: func(ctx *cli.Context) error {
systemOk, systemString := sprintCheckSystem()
phpOk, phpString := sprintCheckCliExists("php")
symfonyOk, symfonyString := sprintCheckCliExists("symfony")
data := [][]string{
[]string{bold("System"), systemString, "Operating System you run"},
[]string{bold("PHP"), phpString, "PHP runtime"},
[]string{bold("Symfony"), symfonyString, "Symfony CLI"},
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Value", "Description"})
for _, v := range data {
table.Append(v)
}
printHeader()
fmt.Printf("Check needed binaries, %s means everything is ok, \n", green("green status"))
fmt.Printf("%s means you have to install corresponding binary.\n", red("red status"))
table.Render()
if systemOk == false || phpOk == false || symfonyOk == false {
fmt.Printf("We saw atleast one missing binary, you can run %s to fix it.\n", yellow("pomdok install"))
} else {
fmt.Printf("Everything is fine, you can start using %s 🎉.\n", yellow("pomdok"))
}
return nil
},
}
func sprintCheckSystem() (bool, string) {
system := runtime.GOOS
if system == "linux" || system == "darwin" {
return true, green(system)
}
return false, red(system)
}
func sprintCheckCliExists(command string) (bool, string) {
exists, out := checkBinaryExists(command)
if exists {
out = green(out)
} else {
out = red("Not-found")
}
return exists, out
}