Esempio n. 1
0
File: main.go Progetto: bjarneh/cmd
func parseArgv() {

	getopt := gopt.New()

	getopt.BoolOption("-h -help --help")
	getopt.BoolOption("-r -regex --regex")
	getopt.BoolOption("-p -posix --posix")

	rest := getopt.Parse(os.Args[1:])

	if getopt.IsSet("-help") {
		help = true
	}

	if getopt.IsSet("-regex") {
		regx = true
	}

	if getopt.IsSet("-posix") {
		posix = true
	}

	if len(rest) > 0 {
		pattern = rest[0]
	}

}
Esempio n. 2
0
File: main.go Progetto: bjarneh/cmd
func init() {

	getopt = gopt.New()

	getopt.BoolOption("-h -help --help help")
	getopt.BoolOption("-l -list --list")
	getopt.BoolOption("-v -verbose --verbose")
	getopt.StringOptionFancy("-m --match")

	addMatchFunc(match)
}
Esempio n. 3
0
File: main.go Progetto: bjarneh/cmd
func parseArgv() {

	getopt := gopt.New()

	getopt.BoolOption("-h -help --help")
	getopt.BoolOption("-r -regex --regex")
	getopt.BoolOption("-p -posix --posix")
	getopt.BoolOption("-l -lower --lower")
	getopt.BoolOption("-i -include --include")
	getopt.StringOptionFancy("-d --dir")

	rest := getopt.Parse(os.Args[1:])

	if getopt.IsSet("-help") {
		help = true
	}

	if getopt.IsSet("-regex") {
		regx = true
	}

	if getopt.IsSet("-dir") {
		topdir = getopt.Get("-dir")
	}

	if getopt.IsSet("-posix") {
		posix = true
	}

	if getopt.IsSet("-lower") {
		lower = true
	}

	if getopt.IsSet("-include") {
		include = true
	}

	if len(rest) > 0 {
		pattern = rest[0]
	}

}
Esempio n. 4
0
func TestGetOpt(t *testing.T) {

	getopt := gopt.New()

	getopt.BoolOption("-h -help --help")
	getopt.BoolOption("-v -version --version")
	getopt.StringOption("-f -file --file --file=")
	getopt.StringOption("-num=")
	getopt.StringOption("-I")

	argv := strings.Split("-h -num=7 -version not-option -fsomething -I/dir1 -I/dir2", " ")

	args := getopt.Parse(argv)

	if !getopt.IsSet("-help") {
		t.Fatal("! getopt.IsSet('-help')\n")
	}

	if !getopt.IsSet("-version") {
		t.Fatal(" ! getopt.IsSet('-version')\n")
	}

	if !getopt.IsSet("-file") {
		t.Fatal(" ! getopt.IsSet('-file')\n")
	} else {
		if getopt.Get("-f") != "something" {
			t.Fatal(" getopt.Get('-f') != 'something'\n")
		}
	}

	if !getopt.IsSet("-num=") {
		t.Fatal(" ! getopt.IsSet('-num=')\n")
	} else {
		n, e := getopt.GetInt("-num=")
		if e != nil {
			t.Fatalf(" getopt.GetInt error = %s\n", e)
		}
		if n != 7 {
			t.Fatalf(" getopt.GetInt != 7 (%d)\n", n)
		}
	}

	if !getopt.IsSet("-I") {
		t.Fatal(" ! getopt.IsSet('-I')\n")
	} else {
		elms := getopt.GetMultiple("-I")
		if len(elms) != 2 {
			t.Fatal("getopt.GetMultiple('-I') != 2\n")
		}
		if elms[0] != "/dir1" {
			t.Fatal("getopt.GetMultiple('-I')[0] != '/dir1'\n")
		}
		if elms[1] != "/dir2" {
			t.Fatal("getopt.GetMultiple('-I')[1] != '/dir2'\n")
		}
	}

	if len(args) != 1 {
		t.Fatal("len(remaining) != 1\n")
	}

	if args[0] != "not-option" {
		t.Fatal("remaining[0] != 'not-something'\n")
	}
}
Esempio n. 5
0
File: main.go Progetto: ssrl/mgd
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", "")

}
Esempio n. 6
0
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", "")

}
Esempio n. 7
0
File: main.go Progetto: bjarneh/cmd
func init() {
	getopt = gopt.New()
	getopt.BoolOption("-h -help --help")
	getopt.BoolOption("-r -recursive --recursive")
}