Merge pull request #36 from unistack-org/double_init
add check for already defined flag
This commit is contained in:
commit
19bf7ef965
4
flag.go
4
flag.go
@ -60,7 +60,9 @@ func (c *flagConfig) Init(opts ...config.Option) error {
|
|||||||
if vi == nil {
|
if vi == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if f := flag.Lookup(fn); f != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
switch vi.(type) {
|
switch vi.(type) {
|
||||||
case time.Duration:
|
case time.Duration:
|
||||||
err = c.flagDuration(sf.Value, fn, fv, fd)
|
err = c.flagDuration(sf.Value, fn, fv, fd)
|
||||||
|
@ -43,6 +43,11 @@ func TestLoad(t *testing.T) {
|
|||||||
t.Fatalf("init failed: %v", err)
|
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 {
|
if err := c.Load(ctx); err != nil {
|
||||||
t.Fatalf("load failed: %v", err)
|
t.Fatalf("load failed: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user