diff --git a/flag.go b/flag.go index 66984bf..03e8ed6 100644 --- a/flag.go +++ b/flag.go @@ -139,6 +139,10 @@ func NewFVSet(v interface{}) (*FVSet, error) { } } } + flags.BoolFunc("help", "Show help", func(s string) error { + flags.Usage() + return nil + }) return &FVSet{ Name: name, Value: &v, diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fd35027 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.pyer.club/kingecg/command + +go 1.23.1 diff --git a/test/main.go b/test/main.go new file mode 100644 index 0000000..81cea16 --- /dev/null +++ b/test/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "os" + + "git.pyer.club/kingecg/command" +) + +func main() { + type targs struct { + Test string `flag_default:"test" flag_usage:"this is test"` + TestBool bool `flag_short:"b"` + TestInt int + } + sargs := &targs{} + v, _ := command.NewFVSet(sargs) + v.Parse(os.Args[1:]) + fmt.Println(sargs) +}