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
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, flag.ExitOnError)
Do see the post by Max for a more explicit explanation.