Skip to content

Commit 1c2fe6b

Browse files
committed
style: better update notifier display
1 parent 6b2f73b commit 1c2fe6b

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

cmd/version.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var VersionCmd = &cobra.Command{
2020

2121
newVersion, _ := update.CheckForUpdates()
2222
if newVersion != "" {
23-
cmd.Printf("\nNew version available: %s\n", newVersion)
24-
cmd.Printf("Download it at https://github.com/everdrone/grab/releases/latest\n")
23+
cmd.Printf("\nNew version available %s → %s\n", config.Version, newVersion)
24+
cmd.Printf("https://github.com/everdrone/grab/releases/latest\n")
2525
}
2626
},
2727
}

cmd/version_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func TestVersionCmd(t *testing.T) {
3333
w.Write([]byte(`{"tag_name": "v987.654.321"}`))
3434
},
3535
want: "grab v" + config.Version + " " + config.BuildOS + "/" + config.BuildArch + " (" + config.CommitHash[:7] + ")\n\n" +
36-
"New version available: v987.654.321\n" +
37-
"Download it at https://github.com/everdrone/grab/releases/latest\n",
36+
"New version available " + config.Version + " → 987.654.321\n" +
37+
"https://github.com/everdrone/grab/releases/latest\n",
3838
},
3939
}
4040

internal/update/check.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ func CheckForUpdates() (string, error) {
3232
return "", fmt.Errorf("no tag name")
3333
}
3434

35-
if version, ok := tagName.(string); ok {
36-
if version[0] != 'v' {
37-
version = "v" + version
35+
if latest, ok := tagName.(string); ok {
36+
if latest[0] != 'v' {
37+
latest = "v" + latest
3838
}
3939

40-
if !semver.IsValid(version) {
41-
return "", fmt.Errorf("invalid version: %s", version)
40+
if !semver.IsValid(latest) {
41+
return "", fmt.Errorf("invalid version: %s", latest)
4242
}
4343

44-
if semver.Compare(version, "v"+config.Version) == 1 {
45-
return version, nil
44+
current := "v" + config.Version
45+
46+
if semver.Compare(latest, current) == 1 {
47+
return latest[1:], nil
4648
}
4749
} else {
4850
return "", fmt.Errorf("invalid tag name")

internal/update/check_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestCheckForUpdates(t *testing.T) {
7979
handler: func(w http.ResponseWriter, r *http.Request) {
8080
w.Write([]byte(`{"tag_name": "v987.654.321"}`))
8181
},
82-
want: "v987.654.321",
82+
want: "987.654.321",
8383
wantErr: false,
8484
},
8585
}

0 commit comments

Comments
 (0)