add help to flag set
This commit is contained in:
parent
525a2ad966
commit
6fd5111300
4
flag.go
4
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,
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue