This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flags.go
95 lines (78 loc) · 1.93 KB
/
flags.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package config
import (
"time"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
/*
Creation Time: 2020 - Jun - 16
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
Copyright Ronak Software Group 2020
*/
type FlagOption func(fs *pflag.FlagSet)
func SetFlags(cmd *cobra.Command, opts ...FlagOption) {
for _, opt := range opts {
opt(cmd.Flags())
}
}
func SetPersistentFlags(cmd *cobra.Command, opts ...FlagOption) {
for _, opt := range opts {
opt(cmd.PersistentFlags())
}
}
/*
Flags
*/
func StringFlag(name, value, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.String(name, value, usage)
}
}
func IntFlag(name string, value int, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Int(name, value, usage)
}
}
func Int32Flag(name string, value int32, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Int32(name, value, usage)
}
}
func Uint32Flag(name string, value uint32, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Uint32(name, value, usage)
}
}
func Int64Flag(name string, value int64, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Int64(name, value, usage)
}
}
func Uint64Flag(name string, value uint64, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Uint64(name, value, usage)
}
}
func BoolFlag(name string, value bool, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Bool(name, value, usage)
}
}
func DurationFlag(name string, value time.Duration, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Duration(name, value, usage)
}
}
func StringSliceFlag(name string, value []string, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.StringSlice(name, value, usage)
}
}
func Int64SliceFlag(name string, value []int64, usage string) FlagOption {
return func(fs *pflag.FlagSet) {
fs.Int64Slice(name, value, usage)
}
}