summaryrefslogtreecommitdiff
path: root/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/utilities/string_array_flag.go
blob: d224ab776c0cb4fd7906d6dfd9c4aa8dbeecf2e0 (plain)
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
package utilities

import (
	"flag"
	"strings"
)

// flagInterface is an cut down interface to `flag`
type flagInterface interface {
	Var(value flag.Value, name string, usage string)
}

// StringArrayFlag defines a flag with the specified name and usage string.
// The return value is the address of a `StringArrayFlags` variable that stores the repeated values of the flag.
func StringArrayFlag(f flagInterface, name string, usage string) *StringArrayFlags {
	value := &StringArrayFlags{}
	f.Var(value, name, usage)
	return value
}

// StringArrayFlags is a wrapper of `[]string` to provider an interface for `flag.Var`
type StringArrayFlags []string

// String returns a string representation of `StringArrayFlags`
func (i *StringArrayFlags) String() string {
	return strings.Join(*i, ",")
}

// Set appends a value to `StringArrayFlags`
func (i *StringArrayFlags) Set(value string) error {
	*i = append(*i, value)
	return nil
}