diff --git a/main.go b/main.go index 5046f39..2f04842 100644 --- a/main.go +++ b/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) } diff --git a/selfupdate/selfupdate_test.go b/selfupdate/selfupdate_test.go index a679db3..84bac00 100644 --- a/selfupdate/selfupdate_test.go +++ b/selfupdate/selfupdate_test.go @@ -1,8 +1,7 @@ package selfupdate -import ( - "testing" -) +import "testing" + +func TestUpdater(t *testing.T) { -func TestUpdater() { }