add check for already defined flag #36

Merged
vtolstov merged 2 commits from double_init into v3 2022-03-25 14:10:20 +03:00
2 changed files with 8 additions and 1 deletions
Showing only changes of commit 1dd7e71881 - Show all commits

View File

@ -60,7 +60,9 @@ func (c *flagConfig) Init(opts ...config.Option) error {
if vi == nil {
continue
}
if f := flag.Lookup(fn); f != nil {
return nil
}
switch vi.(type) {
case time.Duration:
err = c.flagDuration(sf.Value, fn, fv, fd)

View File

@ -43,6 +43,11 @@ func TestLoad(t *testing.T) {
t.Fatalf("init failed: %v", err)
}
// double init test
if err := c.Init(); err != nil {
t.Fatalf("init failed: %v", err)
}
if err := c.Load(ctx); err != nil {
t.Fatalf("load failed: %v", err)
}