Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 1.01 KB

flag_redefined.md

File metadata and controls

26 lines (17 loc) · 1.01 KB

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