10
type int64SliceValue struct {
15
func newInt64SliceValue(val []int64, p *[]int64) *int64SliceValue {
16
isv := new(int64SliceValue)
22
func (s *int64SliceValue) Set(val string) error {
23
ss := strings.Split(val, ",")
24
out := make([]int64, len(ss))
25
for i, d := range ss {
27
out[i], err = strconv.ParseInt(d, 0, 64)
36
*s.value = append(*s.value, out...)
42
func (s *int64SliceValue) Type() string {
46
func (s *int64SliceValue) String() string {
47
out := make([]string, len(*s.value))
48
for i, d := range *s.value {
49
out[i] = fmt.Sprintf("%d", d)
51
return "[" + strings.Join(out, ",") + "]"
54
func (s *int64SliceValue) fromString(val string) (int64, error) {
55
return strconv.ParseInt(val, 0, 64)
58
func (s *int64SliceValue) toString(val int64) string {
59
return fmt.Sprintf("%d", val)
62
func (s *int64SliceValue) Append(val string) error {
63
i, err := s.fromString(val)
67
*s.value = append(*s.value, i)
71
func (s *int64SliceValue) Replace(val []string) error {
72
out := make([]int64, len(val))
73
for i, d := range val {
75
out[i], err = s.fromString(d)
84
func (s *int64SliceValue) GetSlice() []string {
85
out := make([]string, len(*s.value))
86
for i, d := range *s.value {
87
out[i] = s.toString(d)
92
func int64SliceConv(val string) (interface{}, error) {
93
val = strings.Trim(val, "[]")
94
// Empty string would cause a slice with one (empty) entry
98
ss := strings.Split(val, ",")
99
out := make([]int64, len(ss))
100
for i, d := range ss {
102
out[i], err = strconv.ParseInt(d, 0, 64)
111
// GetInt64Slice return the []int64 value of a flag with the given name
112
func (f *FlagSet) GetInt64Slice(name string) ([]int64, error) {
113
val, err := f.getFlagType(name, "int64Slice", int64SliceConv)
115
return []int64{}, err
117
return val.([]int64), nil
120
// Int64SliceVar defines a int64Slice flag with specified name, default value, and usage string.
121
// The argument p points to a []int64 variable in which to store the value of the flag.
122
func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string) {
123
f.VarP(newInt64SliceValue(value, p), name, "", usage)
126
// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
127
func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) {
128
f.VarP(newInt64SliceValue(value, p), name, shorthand, usage)
131
// Int64SliceVar defines a int64[] flag with specified name, default value, and usage string.
132
// The argument p points to a int64[] variable in which to store the value of the flag.
133
func Int64SliceVar(p *[]int64, name string, value []int64, usage string) {
134
CommandLine.VarP(newInt64SliceValue(value, p), name, "", usage)
137
// Int64SliceVarP is like Int64SliceVar, but accepts a shorthand letter that can be used after a single dash.
138
func Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string) {
139
CommandLine.VarP(newInt64SliceValue(value, p), name, shorthand, usage)
142
// Int64Slice defines a []int64 flag with specified name, default value, and usage string.
143
// The return value is the address of a []int64 variable that stores the value of the flag.
144
func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64 {
146
f.Int64SliceVarP(&p, name, "", value, usage)
150
// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
151
func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 {
153
f.Int64SliceVarP(&p, name, shorthand, value, usage)
157
// Int64Slice defines a []int64 flag with specified name, default value, and usage string.
158
// The return value is the address of a []int64 variable that stores the value of the flag.
159
func Int64Slice(name string, value []int64, usage string) *[]int64 {
160
return CommandLine.Int64SliceP(name, "", value, usage)
163
// Int64SliceP is like Int64Slice, but accepts a shorthand letter that can be used after a single dash.
164
func Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64 {
165
return CommandLine.Int64SliceP(name, shorthand, value, usage)