VictoriaMetrics/lib/flagutil/array.go

29 lines
554 B
Go
Raw Normal View History

2019-05-22 23:16:55 +02:00
package flagutil
2019-06-18 09:26:44 +02:00
import (
"flag"
"strings"
)
// NewArray returns new Array with the given name and descprition.
func NewArray(name, description string) *Array {
var a Array
flag.Var(&a, name, description)
return &a
}
2019-05-22 23:16:55 +02:00
// Array holds an array of flag values
type Array []string
// String implements flag.Value interface
func (a *Array) String() string {
return strings.Join(*a, ",")
}
// Set implements flag.Value interface
func (a *Array) Set(value string) error {
values := strings.Split(value, ",")
*a = append(*a, values...)
return nil
}