Skip to content

Commit

Permalink
Add IsUpdateAvailable function to check for newer versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rabilrbl committed Jan 26, 2024
1 parent 8b03094 commit ece7d60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,22 @@ func atoiOrZero(s string) int {
i, _ := strconv.Atoi(s)
return i
}

// IsUpdateAvailable checks if a newer version of the application is available
// by calling getLatestRelease() to fetch the latest release
// information from GitHub.
func IsUpdateAvailable(currentVersion, customVersion string) string {
release, err := getLatestRelease(customVersion)
if err != nil {
return ""
}

latestVersion := release.TagName

// Compare versions
if customVersion == "" && compareVersions(currentVersion, latestVersion) >= 0 {
return ""
}

return latestVersion
}
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func main() {
Copyright: "© JioTV Go by Mohammed Rabil (https://github.com/rabilrbl/jiotv_go)",
Compiled: time.Now(),
Suggest: true,
Before: func(c *cli.Context) error {
isUpdateAvailableVersion := cmd.IsUpdateAvailable(c.App.Version, "")
if isUpdateAvailableVersion != "" {
fmt.Printf("Newer version %s available. Run `jiotv_go update` to update.\n", isUpdateAvailableVersion)
}
return nil
},
Commands: []*cli.Command{
{
Name: "serve",
Expand Down

0 comments on commit ece7d60

Please sign in to comment.