diff --git a/Changelog.md b/Changelog.md index 7482ef3..a49f3b6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,9 +3,11 @@ All notable changes to this project will be documented in this file. The format # [0.9.3] - 2022-04-16 ## Changed -- Parallelized update process -- Simplified messages during the update process -- Improved error messages +- Parallelized update subcommand process +- Parallelized check subcommand process +- Simplified messages during the update/check process +- Display the latest version after an update in an easily recognizable color +- Improved error messages. # [0.9.1] - 2022-03-19 ## Changed - Changed the message at the time of update was incorrect, so the message was corrected. diff --git a/cmd/check.go b/cmd/check.go index a2648ef..e4bcdc6 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -50,28 +50,44 @@ func doCheck(pkgs []goutil.Package) int { needUpdatePkgs := []goutil.Package{} print.Info("check binary under $GOPATH/bin or $GOBIN") - for i, v := range pkgs { - if v.ModulePath == "" { - print.Err(fmt.Errorf(countFmt+" check failure: %s", - i+1, len(pkgs), v.Name)) - result = 1 - continue + ch := make(chan updateResult) + checker := func(p goutil.Package, result chan updateResult) { + var err error + if p.ModulePath == "" { + err = fmt.Errorf(" %s is not installed by 'go install' (or permission incorrect)", p.Name) + } else { + var latestVer string + latestVer, err = goutil.GetLatestVer(p.ModulePath) + if err != nil { + err = fmt.Errorf(" %s %w", p.Name, err) + } + p.Version.Latest = latestVer + if !goutil.IsAlreadyUpToDate(*p.Version) { + needUpdatePkgs = append(needUpdatePkgs, p) + } } - latestVer, err := goutil.GetLatestVer(v.ModulePath) - if err != nil { - print.Err(fmt.Errorf(countFmt+" check failure: %w", - i+1, len(pkgs), err)) - result = 1 - continue + r := updateResult{ + pkg: p, + err: err, } - v.Version.Latest = latestVer + result <- r + } - print.Info(fmt.Sprintf(countFmt+" check success: %s (%s)", - i+1, len(pkgs), v.ModulePath, v.VersionCheckResultStr())) + // check all package + for _, v := range pkgs { + go checker(v, ch) + } - if !goutil.IsAlreadyUpToDate(*v.Version) { - needUpdatePkgs = append(needUpdatePkgs, v) + // print result + for i := 0; i < len(pkgs); i++ { + v := <-ch + if v.err == nil { + print.Info(fmt.Sprintf(countFmt+" %s (%s)", + i+1, len(pkgs), v.pkg.ModulePath, v.pkg.VersionCheckResultStr())) + } else { + result = 1 + print.Err(fmt.Errorf(countFmt+"%s", i+1, len(pkgs), v.err.Error())) } } diff --git a/doc/img/sample.png b/doc/img/sample.png index b970b85..a42d5d0 100644 Binary files a/doc/img/sample.png and b/doc/img/sample.png differ diff --git a/internal/goutil/goutil.go b/internal/goutil/goutil.go index 06bff1b..b0cddf3 100644 --- a/internal/goutil/goutil.go +++ b/internal/goutil/goutil.go @@ -67,7 +67,7 @@ func (p *Package) CurrentToLatestStr() string { if IsAlreadyUpToDate(*p.Version) { return "Already up-to-date: " + color.GreenString(p.Version.Latest) } - return color.GreenString(p.Version.Current) + " to " + color.GreenString(p.Version.Latest) + return color.GreenString(p.Version.Current) + " to " + color.YellowString(p.Version.Latest) } // VersionCheckResultStr returns string about command version check. @@ -75,7 +75,7 @@ func (p *Package) VersionCheckResultStr() string { if IsAlreadyUpToDate(*p.Version) { return "Already up-to-date: " + color.GreenString(p.Version.Latest) } - return "current: " + color.GreenString(p.Version.Current) + ", latest: " + color.GreenString(p.Version.Latest) + return "current: " + color.GreenString(p.Version.Current) + ", latest: " + color.YellowString(p.Version.Latest) } // IsAlreadyUpToDate return whether binary is already up to date or not.