Panic on 0.7.11
Closed this issue · 2 comments
Was trying to use this as a simple test server and installed it with go get
which pulled in 0.7.11. It panics on any input:
fake-service
fake-service flag redefined: help
panic: fake-service flag redefined: help
goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000c2120, 0x1779aa0, 0xc0000c5a58, 0x16a40b1, 0x4, 0x16adc39, 0x13)
/usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:848 +0x4ae
flag.(*FlagSet).BoolVar(...)
/usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:621
flag.(*FlagSet).Bool(0xc0000c2120, 0x16a40b1, 0x4, 0x0, 0x16adc39, 0x13, 0xc0001682b0)
/usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:634 +0x8a
flag.Bool(0x16a40b1, 0x4, 0xc000110100, 0x16adc39, 0x13, 0x16c5175)
/usr/local/Cellar/go/1.13.8/libexec/src/flag/flag.go:641 +0x5e
main.init()
/Users/banks/src/go/pkg/mod/github.com/nicholasjackson/fake-service@v0.7.11/main.go:70 +0x99b
Note no args/env set there but not found a combination that does work either yet. Also not figured out how far back this goes but it seems like it's a simple issue.
Ah the problem is that env
package also declares a help flag: https://github.com/nicholasjackson/env/blob/3a22e09ec0560832f6ebc69658d9d9c715459e79/env.go#L13
So the help flag declared here will always panic since it's a global namespace. It would be nice if env
didn't declare flags if it's intended for library use and had a separate subpackage for the binary.
go version
go version go1.13.8 darwin/amd64
In case that's relevant.
Ah yeah, fake-service was never designed as a library just a CLI. However, I think it is pretty easy to abstract the CLI and main application.
Let me do that and cut a release so that it is importable for tests etc,