Skip to content

Commit

Permalink
added color support
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed Sep 14, 2023
1 parent 07e4366 commit d5f61ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/meta/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package meta

const VERSION = "v0.2.3"
const VERSION = "v0.2.1"

4 changes: 2 additions & 2 deletions cli/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// I wrote most of it before I remembered that GitHub has an API so expect major refactoring.
func (z *ZVM) Upgrade() error {

upgradable, tagName, err := canIUpgrade()
upgradable, tagName, err := CanIUpgrade()
if err != nil {
return errors.Join(ErrFailedUpgrade, err)

Check failure on line 31 in cli/upgrade.go

View workflow job for this annotation

GitHub Actions / build

undefined: errors.Join
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func isSymlink(path string) (bool, error) {



func canIUpgrade() (bool, string, error) {
func CanIUpgrade() (bool, string, error) {
release, err := getLatestGitHubRelease("tristanisham", "zvm")
if err != nil {
return false, "", err
Expand Down
24 changes: 24 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ func main() {

if len(args) == 0 {
helpMsg()
alertIfUpgradable(zvm.Settings.UseColor)
os.Exit(0)
}

alertIfUpgradable(zvm.Settings.UseColor)

for i, arg := range args {
switch arg {
case "install", "i":
Expand Down Expand Up @@ -128,3 +131,24 @@ func helpMsg() {
return
}
}

// alertIfUpgradable checks to see if a new version of ZVM is out, and alerts the user via stdout.
func alertIfUpgradable(colors bool) {

if _, noCheckUpgrade := os.LookupEnv("ZVM_NO_CHECK_UPDATE"); !noCheckUpgrade {
upgradable, tagName, err := cli.CanIUpgrade()
if err != nil {
log.Info("failed new zvm version check")
}

if upgradable {
coloredText := "zvm upgrade"
if colors {
coloredText = clr.Blue("zvm upgrade")
}

fmt.Printf("There's a new version of ZVM (%s).\n Run '%s' to install it!\n", tagName, coloredText)
}
}

}

0 comments on commit d5f61ed

Please sign in to comment.