til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Flag redefined error

When you are doing a command line application in Go and you start to implement test (see: “Test Main Function”), you might observe errors indicating command line flags being redefined.

I have observed this for --verbose, when my application: stevedore implements a --verbose flag. And the reason seems to be that go test also supports --verbose

The fix is easy, I located this recipe from a blog post by Max Chadwick: “Preventing Flag Conflicts in Go”.

The solution is to add:

flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)

Do see the post by Max for a more explicit explanation.

Resources and References