Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of flags in init() short circuits argument parsing #26

Open
sigmonsays opened this issue Oct 2, 2012 · 1 comment
Open

Use of flags in init() short circuits argument parsing #26

sigmonsays opened this issue Oct 2, 2012 · 1 comment

Comments

@sigmonsays
Copy link
Contributor

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

@sigmonsays
Copy link
Contributor Author

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();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant