diff --git a/tests/replit/main.go b/tests/replit/main.go index 93ad4f8..01696b1 100644 --- a/tests/replit/main.go +++ b/tests/replit/main.go @@ -2,13 +2,11 @@ package main import ( "bytes" - "flag" "fmt" "os" "github.com/sandwich-go/xconf" "github.com/sandwich-go/xconf/tests/replit/config" - "github.com/sandwich-go/xconf/xflag" ) func panicErr(err error) { @@ -61,7 +59,5 @@ func main() { fmt.Println("empty config etcd : ", empteOne.GetETCD()) // {[10.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4] fmt.Println("empty config redis: ", empteOne.GetRedis()) // {[192.168.0.1 192.168.0.2] true {16m40s 16m40s 16m40s}} - xconf.DumpInfo() - xflag.PrintDefaults(flag.CommandLine) - + xconf.Usage() } diff --git a/xconf.go b/xconf.go index a3a3c85..9727f8f 100644 --- a/xconf.go +++ b/xconf.go @@ -195,18 +195,14 @@ func (x *XConf) parse(valPtr interface{}) (err error) { if !got { val, got = parsedOptions["h"] } - if got { - if strings.EqualFold(xutil.StringTrim(val), "xconf") { - // 指定xconf_usage的FlagArgs为空,避免再次触发help逻辑 - xx := New(WithFlagSet(newFlagSetContinueOnError("xconf_usage")), WithFlagArgs(), WithErrorHandling(ContinueOnError)) - cc := NewOptions() - xutil.PanicErr(xx.Parse(cc)) - xx.Usage() - } else { - x.Usage() - } + if got && strings.EqualFold(xutil.StringTrim(val), "xconf") { + // 指定xconf_usage的FlagArgs为空,避免再次触发help逻辑 + xx := New(WithFlagSet(newFlagSetContinueOnError("xconf_usage")), WithFlagArgs(), WithErrorHandling(ContinueOnError)) + cc := NewOptions() + xutil.PanicErr(xx.Parse(cc)) + xx.Usage() } else { - xflag.PrintDefaults(x.cc.FlagSet, x.optionUsage) + x.Usage() } } }