Open sigmonsays opened 11 years ago
calling flag.Parse() in init() breaks flags module
$ cat test/test_redis.go package main import ( "fmt" "flag" redis "Go-Redis" ) func main() { var configfile string flag.StringVar(&configfile, "config", "/etc/config.ini", "configuration file") flag.Parse() fmt.Println("Config file", configfile)
spec := redis.DefaultSpec() _ = spec
--- output ---
go run test/test_redis.go -config /etc/config.ini flag provided but not defined: -config Usage of /tmp/go-build929316002/command-line-arguments/_obj/a.out: -redis:d=false: debug flag for go-redis exit status 2
simple patch to move the invocation of flag.Parse() into a seperate function which must be called manually.
func init() { runtime.GOMAXPROCS(2); +} + +func ParseFlags() { flag.Parse(); }
calling flag.Parse() in init() breaks flags module
$ cat test/test_redis.go package main import ( "fmt" "flag" redis "Go-Redis" ) func main() { var configfile string flag.StringVar(&configfile, "config", "/etc/config.ini", "configuration file") flag.Parse() fmt.Println("Config file", configfile)
--- output ---
go run test/test_redis.go -config /etc/config.ini flag provided but not defined: -config Usage of /tmp/go-build929316002/command-line-arguments/_obj/a.out: -redis:d=false: debug flag for go-redis exit status 2