Accepted answer

flag.Parse() is being called before your flag is defined.

You have to make sure that all flag definitions happen before calling flag.Parse(), usually by defining all flags inside init() functions.

Similar question


If you get this, when running command via docker-compose then you do incorrect quoting. Eg.

    image: kumina/openvpn-exporter:latest
    command: [  
      "--openvpn.status_paths", "/etc/openvpn_exporter/openvpn-status.log",
      "--openvpn.status_paths /etc/openvpn_exporter/openvpn-status.log",

First is correct, second is wrong, because whole line counted as one parameter. You need to split them by passing two separate strings, like in first line.


do not call flag.Parse() in any init()


I'm very late to the party; but is this broken (again) on Go 1.19.5?

I hit the same errors reported on this thread and the same solution reported above ( fixes it.

I see a call to flags.Parse() was added back in go_test.go in v1.18

I am only just learning Go so it'd be nice to have some verification from people more skilled before I report this elsewhere.


If you've migrated to golang 13, it changed the order of the test initializer, so it could lead to something like

flag provided but not defined: -test.timeout

as a possible workaround, you can use

var _ = func() bool {
    return true

that would call test initialization before the application one. More info can be found on the original thread:

Related Query

More Query from same tag