mirror of
https://github.com/taigrr/go-selfupdate
synced 2025-01-18 04:33:12 -08:00
Add command line flags, fix bug
* Add -o flag for setting output directory * Add -platform flag for setting platform manually * Fixes #2
This commit is contained in:
parent
14a25c83a5
commit
19468084c4
38
main.go
38
main.go
@ -5,17 +5,19 @@ import (
|
||||
"compress/gzip"
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/kr/binarydist"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
//"runtime"
|
||||
"runtime"
|
||||
|
||||
"github.com/kr/binarydist"
|
||||
//"encoding/base64"
|
||||
)
|
||||
|
||||
var plat, appPath, version, genDir string
|
||||
var version, genDir string
|
||||
|
||||
type current struct {
|
||||
Version string
|
||||
@ -124,34 +126,32 @@ func createUpdate(path string, platform string) {
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Println("Go-Selfupdate - Enable your Golang applications to self update.\n\n")
|
||||
fmt.Println("Usage:\n")
|
||||
fmt.Println("")
|
||||
fmt.Println("Positional arguments:")
|
||||
fmt.Println("\tSingle platform: go-selfupdate myapp 1.2")
|
||||
fmt.Println("\tCross platform: go-selfupdate /tmp/mybinares/ 1.2")
|
||||
}
|
||||
|
||||
func isArgsPresent() bool {
|
||||
if len(os.Args) < 2 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func createBuildDir() {
|
||||
os.MkdirAll(genDir, 0755)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if isArgsPresent() == false {
|
||||
outputDirFlag := flag.String("o", "public", "Output directory for writing updates")
|
||||
platformFlag := flag.String("platform", runtime.GOOS+"-"+runtime.GOARCH,
|
||||
"Target platform in the form OS-ARCH. Defaults to running os/arch.")
|
||||
|
||||
flag.Parse()
|
||||
if flag.NArg() < 2 {
|
||||
flag.Usage()
|
||||
printUsage()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
plat = os.Getenv("GOOS") + "-" + os.Getenv("GOARCH")
|
||||
appPath = os.Args[1]
|
||||
version = os.Args[2]
|
||||
genDir = "public"
|
||||
platform := *platformFlag
|
||||
appPath := flag.Arg(0)
|
||||
version = flag.Arg(1)
|
||||
genDir = *outputDirFlag
|
||||
|
||||
createBuildDir()
|
||||
|
||||
@ -164,5 +164,5 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
createUpdate(appPath, plat)
|
||||
createUpdate(appPath, platform)
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package selfupdate
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func TestUpdater(t *testing.T) {
|
||||
|
||||
func TestUpdater() {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user