sourcegraph/zoekt

"flag redefined: cpuprofile" with sha1cd v0.3.1, avo v0.6.0

MarcWort opened this issue · 4 comments

Hi, you are using github.com/pjbgf/sha1cd currently in verion 0.3.0. If upgraded to version 0.3.1 it also updates github.com/mmcloughlin/avo to v0.6.0, which defines the flag "cpuprofile" here also defined here:

cpuProfile := flag.String("cpuprofile", "", "write cpu profile to `file`")

Its probably a good idea to create some own FlagSet (NewFlagSet) or do some workaround to keep zoekt updatable in the future.

Maybe it would even be possible to remove the old workaround "cpu_profile" by doing it right this time and consolidate the cpuprofile argument.

cpuProfile := flag.String("cpu_profile", "", "write cpu profile to file")

Steps to reproduce

go get -u ./... && go run ./cmd/zoekt-git-index/

Output:

/tmp/go-build2071650996/b001/exe/zoekt-git-index flag redefined: cpuprofile
panic: /tmp/go-build2071650996/b001/exe/zoekt-git-index flag redefined: cpuprofile

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000f6150, {0x13140e0, 0xc0002f70c0}, {0x10b0cbb, 0xa}, {0x11935ee, 0x1b})
        /opt/go/src/flag/flag.go:1028 +0x37d
flag.(*FlagSet).StringVar(...)
        /opt/go/src/flag/flag.go:879
flag.(*FlagSet).String(0xc0000f6150, {0x10b0cbb, 0xa}, {0x0, 0x0}, {0x11935ee, 0x1b})
        /opt/go/src/flag/flag.go:892 +0xa5
flag.String(...)
        /opt/go/src/flag/flag.go:899
main.run()
        /home/user/github/zoekt/cmd/zoekt-git-index/main.go:49 +0x25a
main.main()
        /home/user/github/zoekt/cmd/zoekt-git-index/main.go:146 +0x13

somewhat related: #756

Thanks for the very detailed report! I'll tackle this now.

Doing a reasonably large refactor due to a misbehaving transitive dependency I'm not so keen on, especially since this is the first time I have run into this in this project. If it happens again I'll happily do that. For now I'll just rename the flag to cpu_profile to be consistent with most of our commands.

Following up here, the maintainer of avo sent a PR to sha1cd to remove the dependency on avo on the root go module and that just landed. So now the extra flags being registered is gone since #898 :)