Re: [go-nuts] tests, init() and flags

2021-11-22 Thread Abdennour Elm
@amit this was my best way : NewFlagSet. This is full example including testing: https://eli.thegreenplace.net/2020/testing-flag-parsing-in-go-programs/ Best On Sunday, April 25, 2021 at 5:43:35 AM UTC+3 amits...@gmail.com wrote: > On Sun, Apr 25, 2021 at 7:10 AM Shivendra Singh > wrote: > > >

Re: [go-nuts] tests, init() and flags

2021-04-24 Thread Amit Saha
On Sun, Apr 25, 2021 at 7:10 AM Shivendra Singh wrote: > > Yes @Jan Mercl absolutely correct!! > > Able to figure out a solution. > Basically the go mod i am using as part of the code is doing something like > this : > func init() { > //reads vars > flag.Parse() > } > > The problem arises when d

Re: [go-nuts] tests, init() and flags

2021-04-24 Thread Shivendra Singh
Yes @Jan Mercl absolutely correct!! Able to figure out a solution. Basically the go mod i am using as part of the code is doing something like this : func init() { //reads vars flag.Parse() } The problem arises when doing flag.Parse() as part of the init. https://github.com/golang/go/issues/318

Re: [go-nuts] tests, init() and flags

2021-04-24 Thread Jan Mercl
On Sat, Apr 24, 2021 at 10:37 PM Shivendra Singh wrote: > ..., now in the init() method it parses flag to read variables such as env > and app name that is required to load the appropriate config. IINM, calling flag.Parse anywhere else than in main() or TestMain() is not really compatible with