Skip to content

Commit

Permalink
fix: usage print
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Jan 12, 2022
1 parent 9778e46 commit 5465e6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
7 changes: 4 additions & 3 deletions xconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 5465e6a

Please sign in to comment.