Skip to content

Commit

Permalink
alerts on new nex version (#174)
Browse files Browse the repository at this point in the history
* alerts on new nex version
  • Loading branch information
jordan-rash authored Apr 15, 2024
1 parent 1c035ea commit c60383d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nex/nex.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
)

func init() {
_ = versionCheck()

ncli.Flag("server", "NATS server urls").Short('s').Envar("NATS_URL").PlaceHolder("URL").StringVar(&Opts.Servers)
ncli.Flag("user", "Username or Token").Envar("NATS_USER").PlaceHolder("USER").StringVar(&Opts.Username)
ncli.Flag("password", "Password").Envar("NATS_PASSWORD").PlaceHolder("PASSWORD").StringVar(&Opts.Password)
Expand Down
50 changes: 50 additions & 0 deletions nex/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
)

func versionCheck() error {
if VERSION == "development" {
return nil
}

res, err := http.Get("https://api.github.com/repos/synadia-io/nex/releases/latest")
if err != nil {
return err
}
defer res.Body.Close()

b, err := io.ReadAll(res.Body)
if err != nil {
return err
}

payload := make(map[string]interface{})
err = json.Unmarshal(b, &payload)
if err != nil {
return err
}

latestTag, ok := payload["tag_name"].(string)
if !ok {
return errors.New("error parsing tag_name")
}

if latestTag != VERSION {
fmt.Printf(`================================================================
🎉 There is a newer version [v%s] of the NEX CLI available 🎉
To update, run:
curl -sSf https://nex.synadia.com/install.sh | sh
================================================================
`,
latestTag)
}

return nil
}

0 comments on commit c60383d

Please sign in to comment.