Move to it's own package

This commit is contained in:
Corey Johnson 2019-11-22 10:55:23 -08:00
parent 30bfca0a2a
commit e95594675d
2 changed files with 7 additions and 5 deletions

View file

@ -6,11 +6,12 @@ import (
"strings"
"github.com/github/gh-cli/command"
"github.com/github/gh-cli/update"
)
func main() {
printUpdateMessage := make(chan func())
go command.CheckForUpdate(printUpdateMessage)
go update.CheckForUpdate(printUpdateMessage)
if cmd, err := command.RootCmd.ExecuteC(); err != nil {
fmt.Fprintln(os.Stderr, err)

View file

@ -1,4 +1,4 @@
package command
package update
import (
"encoding/json"
@ -7,6 +7,7 @@ import (
"net/http"
"os"
"github.com/github/gh-cli/command"
"github.com/github/gh-cli/utils"
"golang.org/x/crypto/ssh/terminal"
)
@ -28,14 +29,14 @@ func CheckForUpdate(handleUpdate chan func()) {
handleUpdate <- nil
}
updateAvailable := latestRelease.Version != Version
updateAvailable := latestRelease.Version != command.Version
if updateAvailable {
handleUpdate <- func() {
fmt.Printf(utils.Cyan(`
A new version of gh is available! %s %s
Changelog: %s
Run 'brew reinstall gh' to update!`)+"\n\n", Version, latestRelease.Version, latestRelease.URL)
Run 'brew reinstall gh' to update!`)+"\n\n", command.Version, latestRelease.Version, latestRelease.URL)
}
} else {
handleUpdate <- nil
@ -57,5 +58,5 @@ func getLatestRelease() (*releaseInfo, error) {
var r releaseInfo
json.Unmarshal(data, &r)
return r, nil
return &r, nil
}