use os.Executable() and .LTE() for safety in example

This commit is contained in:
rhysd 2018-11-06 19:39:58 +09:00
parent 6329a43531
commit db4f96105a
1 changed files with 10 additions and 2 deletions

View File

@ -144,7 +144,7 @@ func confirmAndSelfUpdate() {
} }
v := semver.MustParse(version) v := semver.MustParse(version)
if !found || latest.Version.Equals(v) { if !found || latest.Version.LTE(v) {
log.Println("Current version is the latest") log.Println("Current version is the latest")
return return
} }
@ -159,7 +159,12 @@ func confirmAndSelfUpdate() {
return return
} }
if err := selfupdate.UpdateTo(latest.AssetURL, os.Args[0]); err != nil { exe, err := os.Executable()
if err != nil {
log.Println("Could not locate executable path")
return
}
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil {
log.Println("Error occurred while updating binary:", err) log.Println("Error occurred while updating binary:", err)
return return
} }
@ -171,6 +176,9 @@ If GitHub API token is set to `[token]` section in `gitconfig` or `$GITHUB_TOKEN
this library will use it to call GitHub REST API. It's useful when reaching rate limits or when using this library will use it to call GitHub REST API. It's useful when reaching rate limits or when using
this library with private repositories. this library with private repositories.
Note that `os.Args[0]` is not available since it does not provide a full path to executable. Instead,
please use `os.Executable()`.
Please see [the documentation page][GoDoc] for more detail. Please see [the documentation page][GoDoc] for more detail.
This library should work with [GitHub Enterprise][]. To configure API base URL, please setup `Updater` This library should work with [GitHub Enterprise][]. To configure API base URL, please setup `Updater`