Small doctor improvements

This commit is contained in:
Lea Anthony 2024-04-03 20:48:55 +11:00
commit e91c30fad0
8 changed files with 134 additions and 56 deletions

View file

@ -67,7 +67,7 @@ func diagnoseEnvironment(f *flags.Doctor) error {
wailsTableData = append(wailsTableData, []string{"Package Manager", info.PM.Name()})
}
err = pterm.DefaultTable.WithData(wailsTableData).Render()
err = pterm.DefaultTable.WithBoxed().WithData(wailsTableData).Render()
if err != nil {
return err
}

View file

@ -7,6 +7,7 @@ import (
"runtime/debug"
"slices"
"strconv"
"strings"
"github.com/go-git/go-git/v5"
"github.com/jaypipes/ghw"
@ -65,7 +66,7 @@ func Run() (err error) {
return dep.Path == "github.com/wailsapp/wails/v3"
})
wailsVersion := version.VersionString
wailsVersion := strings.TrimSpace(version.VersionString)
if wailsPackage != nil && wailsPackage.Replace != nil {
wailsVersion = "(local) => " + filepath.ToSlash(wailsPackage.Replace.Path)
// Get the latest commit hash
@ -80,47 +81,13 @@ func Run() (err error) {
platformExtras, ok := getInfo()
dependencies := make(map[string]string)
checkPlatformDependencies(dependencies, &ok)
spinner.Success()
/** Output **/
pterm.DefaultSection.Println("Build Environment")
tableData := pterm.TableData{
{"Wails CLI", wailsVersion},
{"Go Version", runtime.Version()},
}
if buildInfo, _ := debug.ReadBuildInfo(); buildInfo != nil {
buildSettingToName := map[string]string{
"vcs.revision": "Revision",
"vcs.modified": "Modified",
}
for _, buildSetting := range buildInfo.Settings {
name := buildSettingToName[buildSetting.Key]
if name == "" {
continue
}
tableData = append(tableData, []string{name, buildSetting.Value})
}
}
mapKeys := lo.Keys(BuildSettings)
slices.Sort(mapKeys)
for _, key := range mapKeys {
tableData = append(tableData, []string{key, BuildSettings[key]})
}
//// Exit early if PM not found
//if info.PM != nil {
// wailsTableData = append(wailsTableData, []string{"Package Manager", info.PM.Name()})
//}
err = pterm.DefaultTable.WithData(tableData).Render()
if err != nil {
return err
}
pterm.DefaultSection.Println("System")
systemTabledata := pterm.TableData{
@ -133,7 +100,7 @@ func Run() (err error) {
{pterm.Sprint("Architecture"), runtime.GOARCH},
}
mapKeys = lo.Keys(platformExtras)
mapKeys := lo.Keys(platformExtras)
slices.Sort(mapKeys)
for _, key := range mapKeys {
systemTabledata = append(systemTabledata, []string{key, platformExtras[key]})
@ -177,11 +144,66 @@ func Run() (err error) {
//systemTabledata = append(systemTabledata, []string{"CPU", cpu.Processors[0].Model})
err = pterm.DefaultTable.WithData(systemTabledata).Render()
err = pterm.DefaultTable.WithBoxed().WithData(systemTabledata).Render()
if err != nil {
return err
}
// Build Environment
pterm.DefaultSection.Println("Build Environment")
tableData := pterm.TableData{
{"Wails CLI", wailsVersion},
{"Go Version", runtime.Version()},
}
if buildInfo, _ := debug.ReadBuildInfo(); buildInfo != nil {
buildSettingToName := map[string]string{
"vcs.revision": "Revision",
"vcs.modified": "Modified",
}
for _, buildSetting := range buildInfo.Settings {
name := buildSettingToName[buildSetting.Key]
if name == "" {
continue
}
tableData = append(tableData, []string{name, buildSetting.Value})
}
}
mapKeys = lo.Keys(BuildSettings)
slices.Sort(mapKeys)
for _, key := range mapKeys {
tableData = append(tableData, []string{key, BuildSettings[key]})
}
err = pterm.DefaultTable.WithBoxed(true).WithData(tableData).Render()
if err != nil {
return err
}
// Dependencies
pterm.DefaultSection.Println("Dependencies")
dependenciesBox := pterm.DefaultBox.WithTitleBottomCenter().WithTitle(pterm.Gray("*") + " - Optional Dependency")
dependencyTableData := pterm.TableData{}
if len(dependencies) == 0 {
pterm.Info.Println("No dependencies found")
} else {
var optionals pterm.TableData
mapKeys = lo.Keys(dependencies)
for _, key := range mapKeys {
if strings.HasPrefix(dependencies[key], "*") {
optionals = append(optionals, []string{key, dependencies[key]})
} else {
dependencyTableData = append(dependencyTableData, []string{key, dependencies[key]})
}
}
dependencyTableData = append(dependencyTableData, optionals...)
dependenciesTableString, _ := pterm.DefaultTable.WithData(dependencyTableData).Srender()
dependenciesBox.Println(dependenciesTableString)
}
pterm.DefaultSection.Println("Diagnosis")
if !ok {
pterm.Warning.Println("There are some items above that need addressing!")

View file

@ -0,0 +1,30 @@
package doctor
import (
"bytes"
"os/exec"
"strconv"
"strings"
)
func checkCommonDependencies(result map[string]string, ok *bool) {
// Check for npm
npmVersion := []byte("Not Installed. Requires npm >= 7.0.0")
npmVersion, err := exec.Command("npm", "-v").Output()
if err != nil {
*ok = false
} else {
npmVersion = bytes.TrimSpace(npmVersion)
// Check that it's at least version 7 by converting first byte to int and checking if it's >= 7
// Parse the semver string
semver := strings.Split(string(npmVersion), ".")
if len(semver) > 0 {
major, _ := strconv.Atoi(semver[0])
if major < 7 {
*ok = false
npmVersion = append(npmVersion, []byte(". Installed, but requires npm >= 7.0.0")...)
}
}
}
result["npm"] = string(npmVersion)
}

View file

@ -3,6 +3,7 @@
package doctor
import (
"bytes"
"github.com/samber/lo"
"os/exec"
"strings"
@ -31,11 +32,16 @@ func getInfo() (map[string]string, bool) {
result["Apple Silicon"] = appleSilicon
result["CPU"] = getSysctl("machdep.cpu.brand_string")
return result, ok
}
func checkPlatformDependencies(result map[string]string, ok *bool) {
// Check for xcode command line tools
output, err := exec.Command("xcode-select", "-v").Output()
cliToolsVersion := "N/A. Install by running: `xcode-select --install`"
if err != nil {
ok = false
*ok = false
} else {
cliToolsVersion = strings.TrimPrefix(string(output), "xcode-select version ")
cliToolsVersion = strings.TrimSpace(cliToolsVersion)
@ -43,5 +49,15 @@ func getInfo() (map[string]string, bool) {
}
result["Xcode cli tools"] = cliToolsVersion
return result, ok
checkCommonDependencies(result, ok)
// Check for nsis
nsisVersion := []byte("Not Installed. Install with `brew install makensis`.")
output, err = exec.Command("makensis", "-VERSION").Output()
if err == nil && output != nil {
nsisVersion = output
}
nsisVersion = bytes.TrimSpace(nsisVersion)
result["*NSIS"] = string(nsisVersion)
}

View file

@ -2,15 +2,13 @@
package doctor
import (
"github.com/wailsapp/wails/v3/internal/doctor/packagemanager"
"github.com/wailsapp/wails/v3/internal/operatingsystem"
)
func getInfo() (map[string]string, bool) {
result := make(map[string]string)
ok := true
return result, true
}
func checkPlatformDependencies(result map[string]string, ok *bool) {
result := make(map[string]string)
info, _ := operatingsystem.Info()
pm := packagemanager.Find(info.ID)
@ -23,7 +21,7 @@ func getInfo() (map[string]string, bool) {
if dep.Optional {
status = "[Optional] "
} else {
ok = false
*ok = false
}
status += "not installed."
if dep.InstallCommand != "" {
@ -36,5 +34,5 @@ func getInfo() (map[string]string, bool) {
result[dep.Name] = status
}
return result, ok
checkCommonDependencies(result, ok)
}

View file

@ -0,0 +1,10 @@
package doctor
import "testing"
func TestRun(t *testing.T) {
err := Run()
if err != nil {
t.Errorf("TestRun failed: %v", err)
}
}

View file

@ -18,10 +18,6 @@ func getInfo() (map[string]string, bool) {
webviewVersion = "Error:" + err.Error()
}
result["WebView2 Version"] = webviewVersion
// add nsis
result["NSIS"] = getNSISVersion()
return result, ok
}
@ -33,3 +29,9 @@ func getNSISVersion() string {
}
return string(output)
}
func checkPlatformDependencies(result map[string]string, ok *bool) {
checkCommonDependencies(result, ok)
// add nsis
result["NSIS"] = getNSISVersion()
}

View file

@ -1 +1 @@
v3.0.0-alpha.4
v3.0.0-alpha.4