mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 20:21:01 +08:00
[mac] better wails doctor
This commit is contained in:
parent
31cf04a944
commit
be39b293b5
@ -3,7 +3,6 @@ package doctor
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -25,14 +24,12 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
logger := clilogger.New(w)
|
||||
|
||||
app.PrintBanner()
|
||||
logger.Print("Scanning system - please wait...")
|
||||
|
||||
// Get system info
|
||||
info, err := system.GetInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Println("Done.")
|
||||
|
||||
// Start a new tabwriter
|
||||
w := new(tabwriter.Writer)
|
||||
@ -46,18 +43,16 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Version: ", info.OS.Version)
|
||||
fmt.Fprintf(w, "%s\t%s\n", "ID:", info.OS.ID)
|
||||
|
||||
// Exit early if PM not found
|
||||
if info.PM == nil {
|
||||
w.Flush()
|
||||
return nil
|
||||
}
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Package Manager: ", info.PM.Name())
|
||||
|
||||
// Output Go Information
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Go Version:", runtime.Version())
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Platform:", runtime.GOOS)
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Architecture:", runtime.GOARCH)
|
||||
|
||||
// Exit early if PM not found
|
||||
if info.PM != nil {
|
||||
fmt.Fprintf(w, "%s\t%s\n", "Package Manager: ", info.PM.Name())
|
||||
}
|
||||
|
||||
// Output Dependencies Status
|
||||
var dependenciesMissing = []string{}
|
||||
var externalPackages = []*packagemanager.Dependancy{}
|
||||
@ -67,12 +62,14 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
fmt.Fprintf(w, "Dependency\tPackage Name\tStatus\tVersion\n")
|
||||
fmt.Fprintf(w, "----------\t------------\t------\t-------\n")
|
||||
|
||||
hasOptionalDependencies := false
|
||||
// Loop over dependencies
|
||||
for _, dependency := range info.Dependencies {
|
||||
|
||||
name := dependency.Name
|
||||
if dependency.Optional {
|
||||
name += "*"
|
||||
hasOptionalDependencies = true
|
||||
}
|
||||
packageName := "Unknown"
|
||||
status := "Not Found"
|
||||
@ -107,12 +104,13 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, packageName, status, dependency.Version)
|
||||
}
|
||||
fmt.Fprintf(w, "\n")
|
||||
fmt.Fprintf(w, "* - Optional Dependency\n")
|
||||
if hasOptionalDependencies {
|
||||
fmt.Fprintf(w, "\n")
|
||||
fmt.Fprintf(w, "* - Optional Dependency\n")
|
||||
}
|
||||
w.Flush()
|
||||
logger.Println("")
|
||||
logger.Println("Diagnosis")
|
||||
logger.Println("---------\n")
|
||||
logger.Println("---------")
|
||||
|
||||
// Generate an appropriate diagnosis
|
||||
|
||||
@ -121,11 +119,11 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
}
|
||||
|
||||
if dependenciesAvailableRequired != 0 {
|
||||
log.Println("Install required packages using: " + info.Dependencies.InstallAllRequiredCommand())
|
||||
logger.Println("Install required packages using: " + info.Dependencies.InstallAllRequiredCommand())
|
||||
}
|
||||
|
||||
if dependenciesAvailableOptional != 0 {
|
||||
log.Println("Install optional packages using: " + info.Dependencies.InstallAllOptionalCommand())
|
||||
logger.Println("Install optional packages using: " + info.Dependencies.InstallAllOptionalCommand())
|
||||
}
|
||||
|
||||
if len(externalPackages) > 0 {
|
||||
@ -133,18 +131,18 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
|
||||
if p.Optional {
|
||||
print("[Optional] ")
|
||||
}
|
||||
log.Println("Install " + p.Name + ": " + p.InstallCommand)
|
||||
logger.Println("Install " + p.Name + ": " + p.InstallCommand)
|
||||
}
|
||||
}
|
||||
|
||||
if len(dependenciesMissing) != 0 {
|
||||
// TODO: Check if apps are available locally and if so, adjust the diagnosis
|
||||
log.Println("Fatal:")
|
||||
log.Println("Required dependencies missing: " + strings.Join(dependenciesMissing, " "))
|
||||
log.Println("Please read this article on how to resolve this: https://wails.app/guides/resolving-missing-packages")
|
||||
logger.Println("Fatal:")
|
||||
logger.Println("Required dependencies missing: " + strings.Join(dependenciesMissing, " "))
|
||||
logger.Println("Please read this article on how to resolve this: https://wails.app/guides/resolving-missing-packages")
|
||||
}
|
||||
|
||||
log.Println("")
|
||||
logger.Println("")
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -2,7 +2,14 @@
|
||||
|
||||
package system
|
||||
|
||||
import "github.com/wailsapp/wails/v2/internal/system/operatingsystem"
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/system/packagemanager"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/system/operatingsystem"
|
||||
)
|
||||
|
||||
func (i *Info) discover() error {
|
||||
var err error
|
||||
@ -11,5 +18,26 @@ func (i *Info) discover() error {
|
||||
return err
|
||||
}
|
||||
i.OS = osinfo
|
||||
|
||||
// Check for xcode command line tools
|
||||
output, err := exec.Command("xcode-select", "-v").Output()
|
||||
installed := true
|
||||
version := ""
|
||||
if err != nil {
|
||||
installed = false
|
||||
} else {
|
||||
version = strings.TrimPrefix(string(output), "xcode-select version ")
|
||||
version = strings.TrimSuffix(version, ".")
|
||||
}
|
||||
xcodeDep := &packagemanager.Dependancy{
|
||||
Name: "xcode command line tools ",
|
||||
PackageName: "N/A",
|
||||
Installed: installed,
|
||||
InstallCommand: "xcode-select --install",
|
||||
Version: version,
|
||||
Optional: false,
|
||||
External: false,
|
||||
}
|
||||
i.Dependencies = append(i.Dependencies, xcodeDep)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user