-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpflag_test.go
More file actions
37 lines (32 loc) · 798 Bytes
/
pflag_test.go
File metadata and controls
37 lines (32 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package bindflags
import (
"github.com/spf13/pflag"
"testing"
)
func TestBindPFlags(t *testing.T) {
f := pflag.NewFlagSet("test", pflag.ContinueOnError)
s := new(student)
MustBindPFlags(f, s)
f.PrintDefaults()
// -a, --age int age
// -d, --desc string desc
// -n, --name string name (default "ss")
// -s, --sex sex (default true)
//PASS
}
type student struct {
Name string `flag:"Name:name;shorthand:n;value:ss;usage:name of student"`
Age int `flag:"age;a;0;usage:age of student"`
Sex bool `flag:"sex;s;true;sex"`
Desc studentDesc
E []float64 `flag:"e"`
}
type studentDesc string
func (s studentDesc) GetPFlagTag() IpFlagTag {
return &PFlagTag{
Name: "desc",
Shorthand: "d",
Value: "",
Usage: "student description",
}
}