rework map and slice support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
30
flag_test.go
30
flag_test.go
@@ -17,20 +17,26 @@ func TestLoad(t *testing.T) {
|
||||
os.Args = append(os.Args, "-addr", "33,44")
|
||||
os.Args = append(os.Args, "-time", time.RFC822)
|
||||
os.Args = append(os.Args, "-metadata", "key=20")
|
||||
os.Args = append(os.Args, "-components", "all=info,api=debug")
|
||||
type NestedConfig struct {
|
||||
Value string `flag:"name=nested_value"`
|
||||
}
|
||||
type Config struct {
|
||||
Broker string `flag:"name=broker,desc='description with, comma',default='127.0.0.1:9092'"`
|
||||
Verbose bool `flag:"name=verbose,desc='verbose output',default='false'"`
|
||||
Addr []string `flag:"name=addr,desc='addrs',default='127.0.0.1:9092'"`
|
||||
Wait time.Duration `flag:"name=wait,desc='wait time',default='2s'"`
|
||||
Time time.Time `flag:"name=time,desc='some time',default='02 Jan 06 15:04 MST'"`
|
||||
Metadata map[string]int `flag:"name=metadata,desc='some meta',default=''"`
|
||||
WithoutDefault string `flag:"name=without_default,desc='with'"`
|
||||
WithoutDesc string `flag:"name=without_desc,default='without_default'"`
|
||||
WithoutAll string `flag:"name=without_all"`
|
||||
Broker string `flag:"name=broker,desc='description with, comma',default='127.0.0.1:9092'"`
|
||||
Verbose bool `flag:"name=verbose,desc='verbose output',default='false'"`
|
||||
Addr []string `flag:"name=addr,desc='addrs',default='127.0.0.1:9092'"`
|
||||
Wait time.Duration `flag:"name=wait,desc='wait time',default='2s'"`
|
||||
Time time.Time `flag:"name=time,desc='some time',default='02 Jan 06 15:04 MST'"`
|
||||
Metadata map[string]int `flag:"name=metadata,desc='some meta',default=''"`
|
||||
WithoutDefault string `flag:"name=without_default,desc='with'"`
|
||||
WithoutDesc string `flag:"name=without_desc,default='without_default'"`
|
||||
WithoutAll string `flag:"name=without_all"`
|
||||
Components map[string]string `flag:"name=components,desc='components logging'"`
|
||||
Nested *NestedConfig
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
cfg := &Config{}
|
||||
cfg := &Config{Nested: &NestedConfig{}}
|
||||
|
||||
c := NewConfig(config.Struct(cfg), TimeFormat(time.RFC822))
|
||||
if err := c.Init(); err != nil {
|
||||
@@ -47,4 +53,8 @@ func TestLoad(t *testing.T) {
|
||||
if tf := cfg.Time.Format(time.RFC822); tf != "02 Jan 06 15:04 MST" {
|
||||
t.Fatalf("parse time error: %s != %s", tf, "02 Jan 06 15:04 MST")
|
||||
}
|
||||
|
||||
if len(cfg.Components) != 2 {
|
||||
t.Fatalf("cant parse map components %#+v", cfg)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user