flag

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolArrayParser

func BoolArrayParser(flagset ...*goflag.FlagSet) func(string, BoolArr, string) *BoolArr

BoolArrayParser returns a function that creates and registers a BoolArr flag.

func FloatArrayParser

func FloatArrayParser(flagset ...*goflag.FlagSet) func(string, FloatArr, string) *FloatArr

FloatArrayParser returns a function that creates and registers a FloatArr flag.

func IntArrayParser

func IntArrayParser(flagset ...*goflag.FlagSet) func(string, IntArr, string) *IntArr

IntArrayParser returns a function that creates and registers an IntArr flag.

func StringArrayParser

func StringArrayParser(flagset ...*goflag.FlagSet) func(string, StringArr, string) *StringArr

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.

func (*BoolArr) Set

func (b *BoolArr) Set(value string) error

Set implements flag.Value interface. Parses comma-separated booleans or appends a single boolean to the array.

func (BoolArr) String

func (b BoolArr) String() string

String implements flag.Value interface. Returns comma-separated representation.

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.

func (*FloatArr) Set

func (f *FloatArr) Set(value string) error

Set implements flag.Value interface. Parses comma-separated floats or appends a single float to the array.

func (FloatArr) String

func (f FloatArr) String() string

String implements flag.Value interface. Returns comma-separated representation.

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.

func (*IntArr) Set

func (i *IntArr) Set(value string) error

Set implements flag.Value interface. Parses comma-separated integers or appends a single integer to the array.

func (IntArr) String

func (i IntArr) String() string

String implements flag.Value interface. Returns comma-separated representation.

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.

func (*StringArr) Set

func (s *StringArr) Set(value string) error

Set implements flag.Value interface. Parses comma-separated values or appends a single value to the array.

func (StringArr) String

func (s StringArr) String() string

String implements flag.Value interface. Returns comma-separated representation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL