We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go version go1.14.1 windows/amd64
i have no try, but i can't find this issue on the Issues
go env
set GO111MODULE=on set GOARCH=amd64 ... set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows ...
$ go env
i want to use two package with two different flag to meet my need, test as follows:
package pk1 import ( "flag" "fmt" ) var pk1Flag = flag.String("pk1", "hello pk1", "test") func init() { flag.Parse() fmt.Println(*pk1Flag) }
package pk2 import ( "flag" "fmt" ) var pk2Flag = flag.String("pk2", "hello pk2", "test") func init() { flag.Parse() fmt.Println(*pk2Flag) }
package main import ( _ "flag/pk1" _ "flag/pk2" "fmt" ) func main() { fmt.Println("main") }
when i use: go run ./main.go or go run ./main.go -pk1=hhhhhh; both of them work well go run .\main.go hello pk1 hello pk2 main go run .\main.go -pk1=hhhhhh hhhhhh hello pk2 main but when using: go run ./main.go -pk2=hhhh or go run ./main.go -pk1=p1 -pk2=p2; both of them do not work
go run .\main.go hello pk1 hello pk2 main go run .\main.go -pk1=hhhhhh hhhhhh hello pk2 main
hello pk1 hhhh main or p1 p2 main
flag provided but not defined: -pk2 Usage of ...\exe\main.exe: -pk1 string test (default "hello pk1") exit status 2
The text was updated successfully, but these errors were encountered:
Never call flag.Parse in init( ) functions. As you just discovered, that doesn't work. See #33190. Closing here since this is not a bug.
flag.Parse
init( )
Sorry, something went wrong.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
i have no try, but i can't find this issue on the Issues
What operating system and processor architecture are you using (
go env
)?set GO111MODULE=on
set GOARCH=amd64
...
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
...
go env
OutputWhat did you do?
i want to use two package with two different flag to meet my need, test as follows:
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: