-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fork.go
53 lines (40 loc) · 1.81 KB
/
fork.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package spec
import (
"reflect"
"github.com/spf13/pflag"
)
type flagSet struct {
*pflag.FlagSet
}
func (f flagSet) IsFork() bool {
return reflect.ValueOf(f.FlagSet).MethodByName("BoolN").IsValid()
}
func (f *flagSet) call(name string, args ...reflect.Value) {
if v := reflect.ValueOf(f.FlagSet).MethodByName(name); v.IsValid() {
v.Call(args)
}
}
func (f *flagSet) BoolN(name, shorthand string, value bool, usage string) {
f.call("BoolN", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}
func (f *flagSet) BoolS(name, shorthand string, value bool, usage string) {
f.call("BoolS", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}
func (f *flagSet) CountN(name, shorthand, usage string) {
f.call("CountN", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(usage))
}
func (f *flagSet) CountS(name, shorthand, usage string) {
f.call("CountS", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(usage))
}
func (f *flagSet) StringSliceN(name, shorthand string, value []string, usage string) {
f.call("StringSliceN", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}
func (f *flagSet) StringSliceS(name, shorthand string, value []string, usage string) {
f.call("StringSliceS", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}
func (f *flagSet) StringN(name, shorthand, value, usage string) {
f.call("StringN", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}
func (f *flagSet) StringS(name, shorthand, value, usage string) {
f.call("StringS", reflect.ValueOf(name), reflect.ValueOf(shorthand), reflect.ValueOf(value), reflect.ValueOf(usage))
}