Skip to content

Commit c84fb6d

Browse files
authored
Merge pull request #25 from nao1215/faster-check
Parallelized check subcommand process
2 parents ef0f6fa + 59da0b4 commit c84fb6d

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

Changelog.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ All notable changes to this project will be documented in this file. The format
33

44
# [0.9.3] - 2022-04-16
55
## Changed
6-
- Parallelized update process
7-
- Simplified messages during the update process
8-
- Improved error messages
6+
- Parallelized update subcommand process
7+
- Parallelized check subcommand process
8+
- Simplified messages during the update/check process
9+
- Display the latest version after an update in an easily recognizable color
10+
- Improved error messages.
911
# [0.9.1] - 2022-03-19
1012
## Changed
1113
- Changed the message at the time of update was incorrect, so the message was corrected.

cmd/check.go

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,44 @@ func doCheck(pkgs []goutil.Package) int {
5050
needUpdatePkgs := []goutil.Package{}
5151

5252
print.Info("check binary under $GOPATH/bin or $GOBIN")
53-
for i, v := range pkgs {
54-
if v.ModulePath == "" {
55-
print.Err(fmt.Errorf(countFmt+" check failure: %s",
56-
i+1, len(pkgs), v.Name))
57-
result = 1
58-
continue
53+
ch := make(chan updateResult)
54+
checker := func(p goutil.Package, result chan updateResult) {
55+
var err error
56+
if p.ModulePath == "" {
57+
err = fmt.Errorf(" %s is not installed by 'go install' (or permission incorrect)", p.Name)
58+
} else {
59+
var latestVer string
60+
latestVer, err = goutil.GetLatestVer(p.ModulePath)
61+
if err != nil {
62+
err = fmt.Errorf(" %s %w", p.Name, err)
63+
}
64+
p.Version.Latest = latestVer
65+
if !goutil.IsAlreadyUpToDate(*p.Version) {
66+
needUpdatePkgs = append(needUpdatePkgs, p)
67+
}
5968
}
6069

61-
latestVer, err := goutil.GetLatestVer(v.ModulePath)
62-
if err != nil {
63-
print.Err(fmt.Errorf(countFmt+" check failure: %w",
64-
i+1, len(pkgs), err))
65-
result = 1
66-
continue
70+
r := updateResult{
71+
pkg: p,
72+
err: err,
6773
}
68-
v.Version.Latest = latestVer
74+
result <- r
75+
}
6976

70-
print.Info(fmt.Sprintf(countFmt+" check success: %s (%s)",
71-
i+1, len(pkgs), v.ModulePath, v.VersionCheckResultStr()))
77+
// check all package
78+
for _, v := range pkgs {
79+
go checker(v, ch)
80+
}
7281

73-
if !goutil.IsAlreadyUpToDate(*v.Version) {
74-
needUpdatePkgs = append(needUpdatePkgs, v)
82+
// print result
83+
for i := 0; i < len(pkgs); i++ {
84+
v := <-ch
85+
if v.err == nil {
86+
print.Info(fmt.Sprintf(countFmt+" %s (%s)",
87+
i+1, len(pkgs), v.pkg.ModulePath, v.pkg.VersionCheckResultStr()))
88+
} else {
89+
result = 1
90+
print.Err(fmt.Errorf(countFmt+"%s", i+1, len(pkgs), v.err.Error()))
7591
}
7692
}
7793

doc/img/sample.png

45.5 KB
Loading

internal/goutil/goutil.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ func (p *Package) CurrentToLatestStr() string {
6767
if IsAlreadyUpToDate(*p.Version) {
6868
return "Already up-to-date: " + color.GreenString(p.Version.Latest)
6969
}
70-
return color.GreenString(p.Version.Current) + " to " + color.GreenString(p.Version.Latest)
70+
return color.GreenString(p.Version.Current) + " to " + color.YellowString(p.Version.Latest)
7171
}
7272

7373
// VersionCheckResultStr returns string about command version check.
7474
func (p *Package) VersionCheckResultStr() string {
7575
if IsAlreadyUpToDate(*p.Version) {
7676
return "Already up-to-date: " + color.GreenString(p.Version.Latest)
7777
}
78-
return "current: " + color.GreenString(p.Version.Current) + ", latest: " + color.GreenString(p.Version.Latest)
78+
return "current: " + color.GreenString(p.Version.Current) + ", latest: " + color.YellowString(p.Version.Latest)
7979
}
8080

8181
// IsAlreadyUpToDate return whether binary is already up to date or not.

0 commit comments

Comments
 (0)