utilflag

package
v0.0.0-...-81154e1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const EmptyFlagName string = "zzz-empty-flag-name"

Special string used to construct a flag in a subset that expect to be equal to the parent set name.

Variables

View Source
var (
	Int8  = makeSignedIntegerFunc[int8](8)
	Int16 = makeSignedIntegerFunc[int16](16)
	Int32 = makeSignedIntegerFunc[int32](32)
	Int64 = makeSignedIntegerFunc[int32](64)

	Uint8  = makeUnsignedIntegerFunc[uint8](8)
	Uint16 = makeUnsignedIntegerFunc[uint16](16)
	Uint32 = makeUnsignedIntegerFunc[uint32](32)
	Uint64 = makeUnsignedIntegerFunc[uint32](64)
)

Registers a flag that parses into an integer with fixed bit size.

View Source
var ErrNoEqual = errors.TagErrorf("ErrNoEqual", "map options expect values in the form k1=v1,k2=v2,k3=v3")

Functions

func AddSubset

func AddSubset(super *pflag.FlagSet, prefix string, subsetFn func(*flag.FlagSet))

func LabelSelector

func LabelSelector(
	fs *flag.FlagSet,
	name string,
	defaultValue labels.Selector,
	usage string,
) *labels.Selector

Registers a flag that parses into a LabelSelector using the labels.Parse syntax.

func LabelSelectorEverything

func LabelSelectorEverything(fs *flag.FlagSet, name string, usage string) *labels.Selector

Registers a flag that parses into a LabelSelector using the labels.Parse syntax and resolves into labels.Everything if unspecified.

func LabelSelectorNothing

func LabelSelectorNothing(fs *flag.FlagSet, name string, usage string) *labels.Selector

Registers a flag that parses into a LabelSelector using the labels.Parse syntax and resolves into labels.Nothing if unspecified.

func Map

func Map[K comparable, V any](
	fs *flag.FlagSet,
	name string,
	defaultValue map[K]V,
	usage string,
	keyParser Parser[K],
	valueParser Parser[V],
) *map[K]V

Registers a flag that accepts a comma-separated list of equal-delimited map entries. If the same key is specified multiple times, the last occurrence wins.

func StringSet

func StringSet(fs *flag.FlagSet, name string, defaultValue []string, usage string) sets.Set[string]

Registers a flag that accepts a comma-separated set of strings.

func StringSlice

func StringSlice(fs *flag.FlagSet, name string, defaultValue []string, usage string) *[]string

Registers a flag that accepts a comma-separated list of strings.

Types

type DefaultEnumValue

type DefaultEnumValue[T any] EnumValue[T]

Similar to EnumValue, but with a defined default.

func (*DefaultEnumValue[T]) Flag

func (enum *DefaultEnumValue[T]) Flag(fs *flag.FlagSet, name string, usage string) *T

Adds the flag to the flag set and returns a box that holds the selected value.

type EnumValue

type EnumValue[T any] struct {
	// contains filtered or unexported fields
}

A type of flag that must resolve to one of the known values of type T.

func EnumFromMap

func EnumFromMap[T any](resolve map[string]T) *EnumValue[T]

Constructs a flag that must resolve to one of the values in the map.

func (*EnumValue[T]) Default

func (enum *EnumValue[T]) Default(key string) *DefaultEnumValue[T]

Assigns a default value for this flag.

func (*EnumValue[T]) Flag

func (enum *EnumValue[T]) Flag(fs *flag.FlagSet, name string, usage string) *optional.Optional[T]

Adds the flag to the flag set and returns a box that holds the selected value.

func (*EnumValue[T]) Set

func (enum *EnumValue[T]) Set(input string) error

func (*EnumValue[T]) String

func (enum *EnumValue[T]) String() string

func (*EnumValue[T]) Type

func (enum *EnumValue[T]) Type() string

Implement pflag.Value.

func (*EnumValue[T]) TypeName

func (enum *EnumValue[T]) TypeName(typeName string) *EnumValue[T]

func (*EnumValue[T]) With

func (enum *EnumValue[T]) With(key string, value T) *EnumValue[T]

type Parser

type Parser[T any] func(string) (T, error)
var StringParser Parser[string] = func(s string) (string, error) { return s, nil }

Jump to

Keyboard shortcuts

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