Skip to content

Commit

Permalink
Add the message on how to update an updatable binary.
Browse files Browse the repository at this point in the history
  • Loading branch information
nao1215 committed Mar 18, 2022
1 parent 02ea0eb commit cbd244f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
23 changes: 23 additions & 0 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/nao1215/gup/internal/goutil"
"github.com/nao1215/gup/internal/print"
Expand Down Expand Up @@ -44,6 +45,7 @@ func check(cmd *cobra.Command, args []string) int {
func doCheck(pkgs []goutil.Package) int {
result := 0
countFmt := "[%" + pkgDigit(pkgs) + "d/%" + pkgDigit(pkgs) + "d]"
needUpdatePkgs := []goutil.Package{}

print.Info("check all binary under $GOPATH/bin or $GOBIN")
for i, v := range pkgs {
Expand All @@ -65,6 +67,27 @@ func doCheck(pkgs []goutil.Package) int {

print.Info(fmt.Sprintf(countFmt+" check success: %s (%s)",
i+1, len(pkgs), v.ModulePath, v.CurrentToLatestStr()))

if !goutil.IsAlreadyUpToDate(*v.Version) {
needUpdatePkgs = append(needUpdatePkgs, v)
}
}

printUpdatablePkgInfo(needUpdatePkgs)
return result
}

func printUpdatablePkgInfo(pkgs []goutil.Package) {
if len(pkgs) == 0 {
return
}

var p string
for _, v := range pkgs {
p += v.Name + " "
}
fmt.Println("")
print.Info("If you want to update binaries, the following command.\n" +
strings.Repeat(" ", 11) +
"$ gup update " + p)
}
7 changes: 6 additions & 1 deletion internal/goutil/goutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ func (p *Package) SetLatestVer() {

// CurrentToLatestStr returns string about the current version and the latest version
func (p *Package) CurrentToLatestStr() string {
if p.Version.Current == p.Version.Latest {
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)
}

// IsAlreadyUpToDate return whether binary is already up to date or not.
func IsAlreadyUpToDate(ver Version) bool {
return ver.Current == ver.Latest
}

// NewGoPaths return GoPaths instance.
func NewGoPaths() *GoPaths {
return &GoPaths{
Expand Down

0 comments on commit cbd244f

Please sign in to comment.