diff --git a/tests/main/main.go b/tests/main/main.go index 338ae86..5891abc 100644 --- a/tests/main/main.go +++ b/tests/main/main.go @@ -10,9 +10,11 @@ import ( func main() { cc := tests.NewTestConfig() cc.Redis.RedisAddress = "127.0.0.1:6637" - if err := xconf.Parse(cc, xconf.WithFiles("c1.yaml"), xconf.WithDebug(false)); err != nil { + xx := xconf.New(xconf.WithFiles("c1.yaml"), xconf.WithDebug(false)) + if err := xx.Parse(cc); err != nil { panic(err) } fmt.Println("cc.RedisAsPointer.RedisAddress ", cc.RedisAsPointer.RedisAddress) fmt.Println("cc.Redis.RedisAddress ", cc.Redis.RedisAddress) + xx.Usage() } diff --git a/xconf.go b/xconf.go index 7803a07..4d57040 100644 --- a/xconf.go +++ b/xconf.go @@ -414,16 +414,17 @@ func (x *XConf) Parse(valPtr interface{}) error { // Usage 打印usage信息 func (x *XConf) Usage(valPtr ...interface{}) { using := x.zeroValPtrForLayout - if len(valPtr) == 0 { + if len(valPtr) != 0 { using = reflect.New(reflect.ValueOf(valPtr).Type().Elem()).Interface() } if using == nil { - x.cc.LogWarning("should parse first") + x.cc.LogWarning("Usage: should parse first") return } lines, magic, err := x.usageLines(using) if err != nil { - x.cc.LogWarning("got error:" + err.Error()) + err = fmt.Errorf("Usage err: " + err.Error()) + x.cc.LogWarning(err.Error()) return } fmt.Fprintln(os.Stderr, xutil.TableFormat(lines, magic))