show latest version and release notes in example

This commit is contained in:
rhysd 2017-12-27 13:01:55 +09:00
parent b709a54c2d
commit ca265cb877
1 changed files with 12 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
"os"
)
@ -11,14 +12,22 @@ const version = "1.2.3"
func selfUpdate() error {
selfupdate.EnableLog()
up, err := selfupdate.TryUpdate(version, "go-github-selfupdate", nil)
latest, err := selfupdate.TryUpdate(version, "go-github-selfupdate", nil)
if err != nil {
return err
}
if up.Version == version {
previous := semver.Make(version)
if previous.Equals(latest.Version) {
fmt.Println("Current binary is the latest version", version)
} else {
fmt.Println("Update successfully done to version", up.Version)
fmt.Printf(
`Update successfully done to version %v
Release note:
%s
`,
latest.Version, latest.Description)
}
}