Merge pull request #4 from Songmu/os-executable

use os.Executable instead of using os.Args[0]
This commit is contained in:
Linda_pp 2018-01-03 00:04:32 +09:00 committed by GitHub
commit 00163d5092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -2,13 +2,14 @@ package selfupdate
import ( import (
"fmt" "fmt"
"github.com/blang/semver"
"github.com/inconshreveable/go-update"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"github.com/blang/semver"
"github.com/inconshreveable/go-update"
) )
// UpdateTo download an executable from assetURL and replace the current binary with the downloaded one. cmdPath is a file path to command executable. // UpdateTo download an executable from assetURL and replace the current binary with the downloaded one. cmdPath is a file path to command executable.
@ -65,5 +66,9 @@ func UpdateCommand(cmdPath string, current semver.Version, slug string) (*Releas
// UpdateSelf updates the running executable itself to the latest version. // UpdateSelf updates the running executable itself to the latest version.
// 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version. // 'slug' represents 'owner/name' repository on GitHub and 'current' means the current version.
func UpdateSelf(current semver.Version, slug string) (*Release, error) { func UpdateSelf(current semver.Version, slug string) (*Release, error) {
return UpdateCommand(os.Args[0], current, slug) cmdPath, err := os.Executable()
if err != nil {
return nil, err
}
return UpdateCommand(cmdPath, current, slug)
} }