From a5861ca9897d99dc7ac0fac7500951b15cfec157 Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Wed, 17 Aug 2022 18:30:30 +0200 Subject: [PATCH] added various error messages and warnings --- compile_report.go | 2 ++ main.go | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/compile_report.go b/compile_report.go index d9a1831..2bc8289 100644 --- a/compile_report.go +++ b/compile_report.go @@ -27,6 +27,8 @@ var ( ColorError = color.New(color.FgRed, color.Bold) ColorInProgress = color.New(color.FgBlue) ColorDone = color.New(color.FgGreen, color.Bold) + + ColorWarn = color.New(color.FgYellow, color.Bold) ) func (s CompileState) String() string { diff --git a/main.go b/main.go index cbb7357..de2247d 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( + "errors" "flag" "fmt" + "os" "os/exec" "path/filepath" "runtime" @@ -31,16 +33,34 @@ func main() { var err error flag.Parse() - if err := FillCompileConfigs(); err != nil { - panic(err) - } - ModulePath, err = filepath.Abs(flag.Arg(0)) if err != nil { panic(err) } ProjectName = filepath.Base(ModulePath) + if _, err := exec.LookPath("go"); err != nil { + ColorError.Fprintln(os.Stderr, "go not found in PATH. compilation not possible") + return + } + + if !*NoCompress { + if _, err := exec.LookPath("upx"); err != nil { + ColorWarn.Fprintln(os.Stderr, "upx not found in PATH. file compression not possible") + *NoCompress = true + } + } + + if err := FillCompileConfigs(); err != nil { + ColorError.Fprintln(os.Stderr, fmt.Errorf("target architectures could not be determined: %w", err)) + return + } + + if _, err := os.Stat(filepath.Join(ModulePath, "go.mod")); errors.Is(err, os.ErrNotExist) { + ColorError.Fprintf(os.Stderr, "no Go module found at '%s'\n", ModulePath) + return + } + ch := make(chan *CompileReport, len(CompileConfigs)) wg := new(sync.WaitGroup)