add help to flag set

This commit is contained in:
程广 2024-11-15 13:17:19 +08:00
parent 525a2ad966
commit 6fd5111300
3 changed files with 27 additions and 0 deletions

View File

@ -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,

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.pyer.club/kingecg/command
go 1.23.1

20
test/main.go Normal file
View File

@ -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)
}