From 891409aedfe6ffccea1c4375220d4ed67c8ab34b Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Thu, 19 May 2016 21:47:53 +0000 Subject: [PATCH] cmd/syncthing: Extract flag parsing. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3126 --- build.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build.go b/build.go index 955455b82..ee1b3b179 100644 --- a/build.go +++ b/build.go @@ -128,12 +128,7 @@ func main() { // might have installed during "build.go setup". os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH"))) - flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") - flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") - flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality") - flag.StringVar(&version, "version", getVersion(), "Set compiled in version string") - flag.BoolVar(&race, "race", race, "Use race detector") - flag.Parse() + parseFlags() switch goarch { case "386", "amd64", "arm", "arm64", "ppc64", "ppc64le": @@ -245,6 +240,15 @@ func setGoPath() { os.Setenv("GOPATH", gopath) } +func parseFlags() { + flag.StringVar(&goarch, "goarch", runtime.GOARCH, "GOARCH") + flag.StringVar(&goos, "goos", runtime.GOOS, "GOOS") + flag.BoolVar(&noupgrade, "no-upgrade", noupgrade, "Disable upgrade functionality") + flag.StringVar(&version, "version", getVersion(), "Set compiled in version string") + flag.BoolVar(&race, "race", race, "Use race detector") + flag.Parse() +} + func checkRequiredGoVersion() (float64, bool) { re := regexp.MustCompile(`go(\d+\.\d+)`) ver := runtime.Version()