score:35
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
- go test flag: flag provided but not defined
- "flag provided but not defined" error in Go test despite the flag being defined in init()?
- Flag provided but not defined
- flag provided but not defined: -test.v
- go build works but go test does not
- In Gogland I get 'flag provided but not defined: -goversion' using go run
- Why do we need to use * to modify values of elementary datatypes but not of user defined structs?
- main.main not defined error when running goapp test
- This code uses the variable "ok" but it is not defined
- Get rid of "flag provided but not defined" when using "flag" package
score:1
If you get this, when running command via docker-compose
then you do incorrect quoting. Eg.
services:
app:
...
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.
score:3
do not call flag.Parse() in any init()
score:3
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 (https://github.com/golang/go/issues/31859#issuecomment-489889428) 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.
score:15
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 {
testing.Init()
return true
}()
that would call test initialization before the application one. More info can be found on the original thread:
https://github.com/golang/go/issues/31859#issuecomment-489889428
Credit To: stackoverflow.com
Related Query
- test command says that the function is not defined
- Go test can access production functions but not test functions
- Why is syscall.SYS_IOCTL defined for Linux but not for Solaris?
- Go test not running specific test despite flag inclusion
- golang append() evaluated but not used
- Why does json.Unmarshal work with reference but not pointer?
- Has Json tag but not exported
- go module @latest found but does not contain package
- Check if Flag Was Provided in Go
- How to test if a channel is close and only send to it when it's not closed
- Go template: can't evaluate field X in type Y (X not part of Y but stuck in a {{range}} loop)
- Go test results in go: cannot find main module, but found .git/config in /Users/dp/Documents
- Template and custom function; panic: function not defined
- sqlmock is not matching query, but query is identical and log output shows the same
- go install does not recognize "-o" flag
- Best way to use test dependencies in Go but prevent export them
- Template unnecessarily escaping `<` to `&lt;` but not `>`
- Why does golang compiler think the variable is declared but not used?
- a comparison equals to true, but when i put it as if condition, why it is not evaluated as true?
- $GOPATH/go.mod exists but should not in AWS Elastic Beanstalk
- Why is there int but not float in Go?
- Trying to use pkg-config but it not being a registered command
- chi.URLParam not working when handler is defined outside main package
- Can't import gorilla/mux (github.com/gorilla/mux@v1.7.4: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt)
- How do I fix $GOPATH/go.mod exists but should not - Linux Fedora
- Why does the capacity of a slice change when you drop the first n items but not the last n items?
- Unit test different flag values
- stderr: $gopath/go.mod exists but should not failed to load view for file:///users/yyy
- $GOPATH/go.mod exists but should not when building docker container, but works if I manually run commands
- Go module is found and replaced, But not required
- fmt.Printf() flag '0' is not ignored for strings
- Error in shift operator using numeric literals but not with numeric constant
- == true evaluated but not used
- Why are string functions not defined on the string type?
- dgrijalva/jwt-go can cast claims to MapClaims but not StandardClaims?
- why is my web browser not sending cookies when I click a link, but it sends them just fine when I type in the url
- Intellisense not working golang test files
- Why do you need to convert a variable to duration but not a raw integer?
- go install @latest found but does not contain package
- glClear() gives GL_OUT_OF_MEMORY on Intel HD 4000 (GL 4.0) but not GeForce (GL 4.2)... why?
More Query from same tag
- Obtain array from slice in Go (language)
- "no root units" error in Dataflow, from PubSub to Bigquery in Golang
- Go Fyne project can't cross compile from Linux to Windows
- Twitter bot with go crashes in Heroku
- Golang: Unmarshal function that can handle 2 different structs
- How to assign multiple handlers to the same uri in go?
- How to pass the empty interface
- Golang undefined variable
- Using Steam Rest API with JSON
- Fetch Data from FormData in Javascript and handle in Golang
- How to get the full name of the local timezone?
- How to convert a flat list of objects with parent field, into a nested tree-like array structure in Golang
- Why does using multiple ethernet connections slow down throughput of I/O bound task
- How to get corresponding fields when selecting specific columns?
- Read whole message with bufio.NewReader(conn)
- Streaming hls video from s3
- sort list by createdDate golang
- In Golang I'm getting the record through exe command. how to print it line by line?
- Is it possible to create a slice from an existing reference?
- If you know the type you're returning, would you still use output arguments?
- How to re-rotate AWS RDS certificates for golang 1.15 compatibility
- Go build with another glibc
- httprouter setting custom NotFound
- How to print numbers in desired order
- How to check if nested pointers access/methods are invalid at runtime
- why I can't convert pointer string to string in Go?
- Golang converting between time formats
- User information by IP address from Active Directory by LDAP query?
- How to render static files within Gin router?
- Why does fmt.Println inside a goroutine not print a line?
- go cannot use output (type string) as type io.Writer in argument to template Execute
- Golang App-engine OAuth Authorization
- How to parse files with arbitrary lengths?
- How to uninstall Go?
- How to fix the error when used golang + vscode