func parseArgv(argv []string) (args []string) { args = getopt.Parse(argv) for _, bkey := range bools { if getopt.IsSet(bkey) { global.SetBool(bkey, true) } } for _, skey := range strs { if getopt.IsSet(skey) { global.SetString(skey, getopt.Get(skey)) } } if getopt.IsSet("-test") || getopt.IsSet("-fmt") { // override IncludeFile to make walker pick _test.go files walker.IncludeFile = func(s string) bool { return strings.HasSuffix(s, ".go") // && // !strings.HasPrefix(filepath.Base(s), "_") } } if getopt.IsSet("-I") { if includes == nil { includes = getopt.GetMultiple("-I") } else { includes = append(includes, getopt.GetMultiple("-I")...) } } getopt.Reset() return args }
func parseArgv(argv []string) (args []string) { args = getopt.Parse(argv) for _, bkey := range bools { if getopt.IsSet(bkey) { global.SetBool(bkey, true) } } for _, skey := range strs { if getopt.IsSet(skey) { global.SetString(skey, getopt.Get(skey)) } } if getopt.IsSet("-test") || getopt.IsSet("-fmt") || getopt.IsSet("-clean") { // override IncludeFile to make walker pick _test.go files walker.IncludeFile = allGoFilesFilter } if getopt.IsSet("-gdmk") { global.SetString("-lib", "_obj") // gdmk does not support testing walker.IncludeFile = noTestFilesFilter } if getopt.IsSet("-I") { includes = append(includes, getopt.GetMultiple("-I")...) } getopt.Reset() return args }
func init() { // initialize option parser getopt = gopt.New() // add all options (bool/string) getopt.BoolOption("-h -help --help help") getopt.BoolOption("-c -clean --clean clean") getopt.BoolOption("-S -static --static") getopt.BoolOption("-v -version --version version") getopt.BoolOption("-s -sort --sort sort") getopt.BoolOption("-p -print --print") getopt.BoolOption("-d -dryrun --dryrun") getopt.BoolOption("-t -test --test test") getopt.BoolOption("-l -list --list") getopt.BoolOption("-q -quiet --quiet") getopt.BoolOption("-V -verbose --verbose") getopt.BoolOption("-f -fmt --fmt") getopt.BoolOption("-tab --tab") getopt.BoolOption("-e -external --external") getopt.StringOption("-a -a= -arch --arch -arch= --arch=") getopt.StringOption("-dot -dot= --dot --dot=") getopt.StringOption("-L -L= -lib -lib= --lib --lib=") getopt.StringOption("-I -I=") getopt.StringOption("-tabwidth --tabwidth -tabwidth= --tabwidth=") getopt.StringOption("-rew-rule --rew-rule -rew-rule= --rew-rule=") getopt.StringOption("-o -o= -output --output -output= --output=") getopt.StringOption("-M -M= -main --main -main= --main=") getopt.StringOption("-b -b= -bench --bench -bench= --bench=") getopt.StringOption("-m -m= -match --match -match= --match=") getopt.StringOption("-test-bin --test-bin -test-bin= --test-bin=") getopt.StringOption("-B -B= -backend --backend -backend= --backend=") getopt.StringOption("-x -x= -exclude --exclude --exclude=") // override IncludeFile to make walker pick up only .go files walker.IncludeFile = func(s string) bool { return strings.HasSuffix(s, ".go") && !strings.HasSuffix(s, "_test.go") // && // !strings.HasPrefix(filepath.Base(s), "_") } // override IncludeDir to make walker ignore 'hidden' directories walker.IncludeDir = func(s string) bool { _, dirname := filepath.Split(s) return dirname[0] != '.' } for _, bkey := range bools { global.SetBool(bkey, false) } for _, skey := range strs { global.SetString(skey, "") } if os.Getenv("GOOS") == "windows" { global.SetString("-test-bin", "gdtest.exe") } else { global.SetString("-test-bin", "gdtest") } global.SetString("-backend", "gc") global.SetString("-lib", "build") global.SetString("-I", "") }
func init() { // initialize option parser getopt = gopt.New() // add all options (bool/string) getopt.BoolOption("-h -help --help help") getopt.BoolOption("-c -clean --clean clean") getopt.BoolOption("-S -static --static") getopt.BoolOption("-v -version --version version") getopt.BoolOption("-s -sort --sort sort") getopt.BoolOption("-p -print --print") getopt.BoolOption("-d -dryrun --dryrun") getopt.BoolOption("-t -test --test test") getopt.BoolOption("-l -list --list") getopt.BoolOption("-q -quiet --quiet") getopt.BoolOption("-V -verbose --verbose") getopt.BoolOption("-f -fmt --fmt") getopt.BoolOption("-T -tab --tab") getopt.BoolOption("-e -external --external") getopt.StringOptionFancy("-a --arch") getopt.StringOptionFancy("-D --dot") getopt.StringOptionFancy("-L --lib") getopt.StringOption("-I -I=") getopt.StringOptionFancy("-g --gdmk") getopt.StringOptionFancy("-w --tabwidth") getopt.StringOptionFancy("-r --rewrite") getopt.StringOptionFancy("-o --output") getopt.StringOptionFancy("-M --main") getopt.StringOptionFancy("-b --bench") getopt.StringOptionFancy("-m --match") getopt.StringOptionFancy("--test-bin") getopt.StringOptionFancy("-B --backend") // new test options and aliases getopt.BoolOption("-test.short --test.short") getopt.BoolOption("-test.v --test.v") getopt.StringOptionFancy("--test.bench") getopt.StringOptionFancy("--test.benchtime") getopt.StringOptionFancy("--test.cpu") getopt.StringOptionFancy("--test.cpuprofile") getopt.StringOptionFancy("--test.memprofile") getopt.StringOptionFancy("--test.memprofilerate") getopt.StringOptionFancy("--test.timeout") // override IncludeFile to make walker pick up only .go files walker.IncludeFile = noTestFilesFilter // override IncludeDir to make walker ignore 'hidden' directories walker.IncludeDir = func(s string) bool { _, dirname := filepath.Split(s) return dirname[0] != '.' } for _, bkey := range bools { global.SetBool(bkey, false) } for _, skey := range strs { global.SetString(skey, "") } // Testing on Windows requires .exe ending if os.Getenv("GOOS") == "windows" { global.SetString("-test-bin", "gdtest.exe") } else { global.SetString("-test-bin", "gdtest") } global.SetString("-backend", "gc") global.SetString("-I", "") }