extra = equals < 0
if extra {
if i+1 >= len(args) {
- usage()
+ testSyntaxError("missing argument for flag " + f.name)
}
value = args[i+1]
}
}
if f.present && !f.multiOK {
- usage()
+ testSyntaxError(f.name + " flag may be set only once")
}
f.present = true
return
func setBoolFlag(flag *bool, value string) {
x, err := strconv.ParseBool(value)
if err != nil {
- fmt.Fprintf(os.Stderr, "go test: illegal bool flag value %s\n", value)
- usage()
+ testSyntaxError("illegal bool flag value " + value)
}
*flag = x
}
func setIntFlag(flag *int, value string) {
x, err := strconv.Atoi(value)
if err != nil {
- fmt.Fprintf(os.Stderr, "go test: illegal int flag value %s\n", value)
- usage()
+ testSyntaxError("illegal int flag value " + value)
}
*flag = x
}
+
+func testSyntaxError(msg string) {
+ fmt.Fprintf(os.Stderr, "go test: %s\n", msg)
+ fmt.Fprintf(os.Stderr, `run "go help test" or "go help testflag" for more information`+"\n")
+ os.Exit(2)
+}