forked from go-flutter-desktop/hover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor.go
120 lines (106 loc) · 3.11 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package cmd
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"github.com/sudonims/hover/cmd/packaging"
"github.com/sudonims/hover/internal/build"
"github.com/sudonims/hover/internal/config"
"github.com/sudonims/hover/internal/log"
"github.com/sudonims/hover/internal/version"
)
func init() {
rootCmd.AddCommand(doctorCmd)
}
var doctorCmd = &cobra.Command{
Use: "doctor",
Short: "Show information about the installed tooling",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return errors.New("does not take arguments")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
assertInFlutterProject()
hoverVersion := version.HoverVersion()
log.Infof("Hover version %s running on %s", hoverVersion, runtime.GOOS)
log.Infof("Sharing packaging tools")
for _, task := range []packaging.Task{
packaging.DarwinBundleTask,
packaging.DarwinDmgTask,
packaging.DarwinPkgTask,
packaging.LinuxAppImageTask,
packaging.LinuxDebTask,
packaging.LinuxPkgTask,
packaging.LinuxRpmTask,
packaging.LinuxSnapTask,
packaging.WindowsMsiTask,
} {
if task.IsSupported() {
log.Infof("%s is supported", task.Name())
}
}
log.Printf("")
log.Infof("Sharing flutter version")
cmdFlutterVersion := exec.Command(build.FlutterBin(), "--version")
cmdFlutterVersion.Stderr = os.Stderr
cmdFlutterVersion.Stdout = os.Stdout
err := cmdFlutterVersion.Run()
if err != nil {
log.Errorf("Flutter --version failed: %v", err)
}
engineCommitHash := version.FlutterRequiredEngineVersion()
log.Infof("Flutter engine commit: %s", log.Au().Magenta("https://github.com/flutter/engine/commit/"+engineCommitHash))
checkFlutterChannel()
cmdGoEnvCC := exec.Command(build.GoBin(), "env", "CC")
cmdGoEnvCCOut, err := cmdGoEnvCC.Output()
if err != nil {
log.Errorf("Go env CC failed: %v", err)
}
cCompiler := strings.Trim(string(cmdGoEnvCCOut), " ")
cCompiler = strings.Trim(cCompiler, "\n")
if cCompiler != "" {
log.Infof("Finding out the C compiler version")
cmdCCVersion := exec.Command(cCompiler, "--version")
cmdCCVersion.Stderr = os.Stderr
cmdCCVersion.Stdout = os.Stdout
cmdCCVersion.Run()
}
log.Infof("Sharing the content of go.mod")
file, err := os.Open(filepath.Join(build.BuildPath, "go.mod"))
if err != nil {
log.Errorf("Failed to read go.mod: %v", err)
} else {
defer file.Close()
b, _ := ioutil.ReadAll(file)
fmt.Print(string(b))
}
hoverConfig, err := config.ReadConfigFile(filepath.Join(build.BuildPath, "hover.yaml"))
if err != nil {
log.Warnf("%v", err)
} else {
log.Infof("Sharing the content of hover.yaml")
dump, err := yaml.Marshal(hoverConfig)
if err != nil {
log.Warnf("%v", err)
} else {
fmt.Print(string(dump))
}
}
log.Infof("Sharing the content of go/cmd")
files, err := filepath.Glob(filepath.Join(build.BuildPath, "cmd", "*"))
if err != nil {
log.Errorf("Failed to get the list of files in go/cmd", err)
os.Exit(1)
}
fmt.Println(strings.Join(files, "\t"))
},
}