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
13 changes: 9 additions & 4 deletions cmd/utilities/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var (
Date = "unknown"
)

var releaseVersionRegex = regexp.MustCompile(`^v?\d+\.\d+\.\d+(-[\w.]+)?$`)

func VersionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Expand Down Expand Up @@ -54,17 +56,16 @@ func GetFormattedDate(inputDate string) string {
func GetChangelogUrl(version string) string {
path := "https://github.com/DylanDevelops/tmpo"

r := regexp.MustCompile(`^v?\d+\.\d+\.\d+(-[\w.]+)?$`)
if !r.MatchString(version) {
if !isReleaseVersion(version) {
return fmt.Sprintf("%s/releases/latest", path)
}

return fmt.Sprintf("%s/releases/tag/v%s", path, strings.TrimPrefix(version, "v"))
}

func checkForUpdates() {
// Only check if we have a valid version (not "dev" or empty)
if Version == "" || Version == "dev" {
// Only check for released semantic versions.
if !isReleaseVersion(Version) {
return
}

Expand All @@ -79,3 +80,7 @@ func checkForUpdates() {
fmt.Printf("%s\n\n", ui.Muted(updateInfo.UpdateURL))
}
}

func isReleaseVersion(version string) bool {
return releaseVersionRegex.MatchString(version)
}
5 changes: 5 additions & 0 deletions cmd/utilities/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func TestGetChangelogUrl(t *testing.T) {
version: "dev",
expected: "https://github.com/DylanDevelops/tmpo/releases/latest",
},
{
name: "unstable version returns latest",
version: "unstable",
expected: "https://github.com/DylanDevelops/tmpo/releases/latest",
},
{
name: "empty version returns latest",
version: "",
Expand Down