Documentation
¶
Overview ¶
Package flag provides custom flag types for parsing array values from command-line arguments. These types implement the flag.Value interface and support both comma-separated values and multiple flag occurrences.
Usage ¶
Single flag with comma-separated values:
./myapp -hosts "host1,host2,host3"
Multiple flag occurrences:
./myapp -hosts host1 -hosts host2 -hosts host3
Available Types ¶
- StringArr: String array flag
- IntArr: Integer array flag
- FloatArr: Float64 array flag
- BoolArr: Boolean array flag
Example ¶
var hosts flag.StringArr
goflag.Var(&hosts, "hosts", "Host addresses")
goflag.Parse()
for _, host := range hosts {
fmt.Println(host)
}
Index ¶
- func BoolArrayParser(flagset ...*goflag.FlagSet) func(string, BoolArr, string) *BoolArr
- func FloatArrayParser(flagset ...*goflag.FlagSet) func(string, FloatArr, string) *FloatArr
- func IntArrayParser(flagset ...*goflag.FlagSet) func(string, IntArr, string) *IntArr
- func StringArrayParser(flagset ...*goflag.FlagSet) func(string, StringArr, string) *StringArr
- type BoolArr
- type FloatArr
- type IntArr
- type StringArr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolArrayParser ¶
BoolArrayParser returns a function that creates and registers a BoolArr flag.
func FloatArrayParser ¶
FloatArrayParser returns a function that creates and registers a FloatArr flag.
func IntArrayParser ¶
IntArrayParser returns a function that creates and registers an IntArr flag.
func StringArrayParser ¶
StringArrayParser returns a function that creates and registers a StringArr flag. This is useful when working with custom FlagSets or the app configuration system.
Example:
parseStringArr := flag.StringArrayParser() hosts := parseStringArr(fs, "hosts", nil, "Host addresses")
Types ¶
type BoolArr ¶
type BoolArr []bool
BoolArr is a boolean slice that implements the flag.Value interface. It supports both comma-separated values and multiple flag occurrences.
type FloatArr ¶
type FloatArr []float64
FloatArr is a float64 slice that implements the flag.Value interface. It supports both comma-separated values and multiple flag occurrences.
type IntArr ¶
type IntArr []int
IntArr is an integer slice that implements the flag.Value interface. It supports both comma-separated values and multiple flag occurrences.
type StringArr ¶
type StringArr []string
StringArr is a string slice that implements the flag.Value interface. It supports both comma-separated values and multiple flag occurrences.