Skip to content

Commit

Permalink
Merge pull request #25 from nao1215/faster-check
Browse files Browse the repository at this point in the history
Parallelized check subcommand process
  • Loading branch information
nao1215 authored Apr 16, 2022
2 parents ef0f6fa + 59da0b4 commit c84fb6d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
8 changes: 5 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 33 additions & 17 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}

Expand Down
Binary file modified doc/img/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions internal/goutil/goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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.
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.
Expand Down

0 comments on commit c84fb6d

Please sign in to comment.