Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/vulnx/clis/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ func showVersion() {
if description != "" {
gologger.Info().Msgf("Current vulnx version %s %s", Version, description)

// If there's a newer version available, provide helpful information
if latestVersion != Version {
// If there's a newer version available, provide helpful information.
// Use the same comparison as the latest/outdated label. A raw
// string compare treats v2.0.2 and 2.0.2 as different releases.
if shouldSuggestUpdate(Version, latestVersion) {
gologger.Info().Msg("To update vulnx, use:")
gologger.Info().Msg("vulnx --update or vulnx update")
gologger.Info().Msg("Or install via pdtm: pdtm -u vulnx")
Expand All @@ -72,6 +74,10 @@ func showVersion() {
}
}

func shouldSuggestUpdate(current, latest string) bool {
return updateutils.IsOutdated(current, latest)
}

func init() {
versionCmd.Flags().BoolVar(&disableUpdateCheck, "disable-update-check", false, "disable automatic update check")
rootCmd.AddCommand(versionCmd)
Expand Down
23 changes: 23 additions & 0 deletions cmd/vulnx/clis/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package clis

import "testing"

func TestShouldSuggestUpdate(t *testing.T) {
tests := []struct {
current string
latest string
want bool
}{
{current: "v2.0.2", latest: "2.0.2", want: false},
{current: "v2.0.2", latest: "v2.0.2", want: false},
{current: "2.0.2", latest: "v2.0.2", want: false},
{current: "v2.0.2", latest: "2.0.3", want: true},
{current: "v2.0.3", latest: "2.0.2", want: false},
}
for _, tt := range tests {
got := shouldSuggestUpdate(tt.current, tt.latest)
if got != tt.want {
t.Errorf("shouldSuggestUpdate(%q, %q) = %v, want %v", tt.current, tt.latest, got, tt.want)
}
}
}
Loading