namsral/flag

Support Multi Value Flags in Config

agorman opened this issue · 0 comments

For some flags I create my own type so I can apply the flag multiple times and store it in a slice. It looks something like this.

./myapp -multi 1 -multi 2 -multi 3

type arrayFlags []string

func (i *arrayFlags) String() string {
	return "[]"
}

func (i *arrayFlags) Set(value string) error {
	*i = append(*i, value)
	return nil
}

var multi arrayFlags

flag.Var(&multi , "multi", "Apply this multiple times")

This works great but when I try to use a config I always only get the first value.

multi 1
multi 2
multi 3

./myapp -config my.conf

The value of multi is always just [1].

Is there a way I can get this to work when using a configuration file?