flagset

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBool

func GetBool(fs *FlagSet, name string) bool

GetBool returns the bool value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetBoolPtr

func GetBoolPtr(fs *FlagSet, name string) *bool

GetBoolPtr returns a pointer to a bool value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetBoolSlice

func GetBoolSlice(fs *FlagSet, name string) []bool

GetBoolSlice returns the []bool value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetBoolSlicePtr

func GetBoolSlicePtr(fs *FlagSet, name string) *[]bool

GetBoolSlicePtr returns a pointer to a []bool value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetCounter

func GetCounter(fs *FlagSet, name string) int

GetCounter returns the uint64 value, reflecting the counter, associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetDuration

func GetDuration(fs *FlagSet, name string) time.Duration

GetDuration returns the time.Duration value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetDurationPtr

func GetDurationPtr(fs *FlagSet, name string) *time.Duration

GetDurationPtr returns a pointer to a time.Duration value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetDurationSlice

func GetDurationSlice(fs *FlagSet, name string) []time.Duration

GetDurationSlice returns the []time.Duration value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetDurationSlicePtr

func GetDurationSlicePtr(fs *FlagSet, name string) *[]time.Duration

GetDurationSlicePtr returns a pointer to a []time.Duration value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetFloat32

func GetFloat32(fs *FlagSet, name string) float32

GetFloat32 returns the float32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetFloat32Ptr

func GetFloat32Ptr(fs *FlagSet, name string) *float32

GetFloat32Ptr returns a pointer to a float32 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetFloat32Slice

func GetFloat32Slice(fs *FlagSet, name string) []float32

GetFloat32Slice returns the []float32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetFloat32SlicePtr

func GetFloat32SlicePtr(fs *FlagSet, name string) *[]float32

GetFloat32SlicePtr returns a pointer to a float64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetFloat64

func GetFloat64(fs *FlagSet, name string) float64

GetFloat64 returns the float64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetFloat64Ptr

func GetFloat64Ptr(fs *FlagSet, name string) *float64

GetFloat64Ptr returns a pointer to a float64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetFloat64Slice

func GetFloat64Slice(fs *FlagSet, name string) []float64

GetFloat64Slice returns the []float64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetFloat64SlicePtr

func GetFloat64SlicePtr(fs *FlagSet, name string) *[]float64

GetFloat64SlicePtr returns a pointer to a []float64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt

func GetInt(fs *FlagSet, name string) int

GetInt returns the int value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt16

func GetInt16(fs *FlagSet, name string) int16

GetInt16 returns the int16 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt16Ptr

func GetInt16Ptr(fs *FlagSet, name string) *int16

GetInt16Ptr returns a pointer to an int16 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt16Slice

func GetInt16Slice(fs *FlagSet, name string) []int16

GetInt16Slice returns the []int16 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt16SlicePtr

func GetInt16SlicePtr(fs *FlagSet, name string) *[]int16

GetInt16SlicePtr returns a pointer to a []int16 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt32

func GetInt32(fs *FlagSet, name string) int32

GetInt32 returns the int32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt32Ptr

func GetInt32Ptr(fs *FlagSet, name string) *int32

GetInt32Ptr returns a pointer to an int32 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt32Slice

func GetInt32Slice(fs *FlagSet, name string) []int32

GetInt32Slice returns the []int32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt32SlicePtr

func GetInt32SlicePtr(fs *FlagSet, name string) *[]int32

GetInt32SlicePtr returns a pointer to a []int32 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt64

func GetInt64(fs *FlagSet, name string) int64

GetInt64 returns the int64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt64Ptr

func GetInt64Ptr(fs *FlagSet, name string) *int64

GetInt64Ptr returns a pointer to an int64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt64Slice

func GetInt64Slice(fs *FlagSet, name string) []int64

GetInt64Slice returns the []int64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt64SlicePtr

func GetInt64SlicePtr(fs *FlagSet, name string) *[]int64

GetInt64SlicePtr returns a pointer to a []int64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt8

func GetInt8(fs *FlagSet, name string) int8

GetInt8 returns the int8 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt8Ptr

func GetInt8Ptr(fs *FlagSet, name string) *int8

GetInt8Ptr returns a pointer to an int8 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetInt8Slice

func GetInt8Slice(fs *FlagSet, name string) []int8

GetInt8Slice returns the []int8 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetInt8SlicePtr

func GetInt8SlicePtr(fs *FlagSet, name string) *[]int8

GetInt8SlicePtr returns a pointer to a []int8 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetIntPtr

func GetIntPtr(fs *FlagSet, name string) *int

GetIntPtr returns a pointer to an int value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetIntSlice

func GetIntSlice(fs *FlagSet, name string) []int

GetIntSlice returns the []int value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetIntSlicePtr

func GetIntSlicePtr(fs *FlagSet, name string) *[]int

GetIntSlicePtr returns a pointer to a []int value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetString

func GetString(fs *FlagSet, name string) string

GetString returns the string value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetStringPtr

func GetStringPtr(fs *FlagSet, name string) *string

GetStringPtr returns a pointer to a string value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetStringSlice

func GetStringSlice(fs *FlagSet, name string) []string

GetStringSlice returns the []string value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetStringSlicePtr

func GetStringSlicePtr(fs *FlagSet, name string) *[]string

GetStringSlicePtr returns a pointer to a []string value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetTypedFlag

func GetTypedFlag[T any](fs *FlagSet, name string) T

GetTypedFlag returns the value of defined type, associated with the given name from the given FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetTypedFlagPtr

func GetTypedFlagPtr[T any](fs *FlagSet, name string) *T

GetTypedFlagPtr returns a pointer to the value of defined type, associated with the given name from the given FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint

func GetUint(fs *FlagSet, name string) uint

GetUint returns the uint value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint16

func GetUint16(fs *FlagSet, name string) uint16

GetUint16 returns the uint16 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint16Ptr

func GetUint16Ptr(fs *FlagSet, name string) *uint16

GetUint16Ptr returns a pointer to an uint16 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint16Slice

func GetUint16Slice(fs *FlagSet, name string) []uint16

GetUint16Slice returns the []uint16 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint16SlicePtr

func GetUint16SlicePtr(fs *FlagSet, name string) *[]uint16

GetUint16SlicePtr returns a pointer to a []uint16 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint32

func GetUint32(fs *FlagSet, name string) uint32

GetUint32 returns the uint32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint32Ptr

func GetUint32Ptr(fs *FlagSet, name string) *uint32

GetUint32Ptr returns a pointer to an uint32 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint32Slice

func GetUint32Slice(fs *FlagSet, name string) []uint32

GetUint32Slice returns the []uint32 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint32SlicePtr

func GetUint32SlicePtr(fs *FlagSet, name string) *[]uint32

GetUint32SlicePtr returns a pointer to a []uint32 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint64

func GetUint64(fs *FlagSet, name string) uint64

GetUint64 returns the uint64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint64Ptr

func GetUint64Ptr(fs *FlagSet, name string) *uint64

GetUint64Ptr returns a pointer to an uint64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint64Slice

func GetUint64Slice(fs *FlagSet, name string) []uint64

GetUint64Slice returns the []uint64 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint64SlicePtr

func GetUint64SlicePtr(fs *FlagSet, name string) *[]uint64

GetUint64SlicePtr returns a pointer to a []uint64 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint8

func GetUint8(fs *FlagSet, name string) uint8

GetUint8 returns the uint8 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint8Ptr

func GetUint8Ptr(fs *FlagSet, name string) *uint8

GetUint8Ptr returns a pointer to an uint8 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUint8Slice

func GetUint8Slice(fs *FlagSet, name string) []uint8

GetUint8Slice returns the []uint8 value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUint8SlicePtr

func GetUint8SlicePtr(fs *FlagSet, name string) *[]uint8

GetUint8SlicePtr returns a pointer to a []uint8 value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUintPtr

func GetUintPtr(fs *FlagSet, name string) *uint

GetUintPtr returns a pointer to an uint value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

func GetUintSlice

func GetUintSlice(fs *FlagSet, name string) []uint

GetUintSlice returns the []uint value associated with the given name from the FlagSet. It will exit with code 1 if:

  • flag does not exist
  • flag value is nil
  • flag value has a different type

func GetUintSlicePtr

func GetUintSlicePtr(fs *FlagSet, name string) *[]uint

GetUintSlicePtr returns a pointer to a []uint value associated with the given name from the FlagSet. If the flag value is not set, it returns nil. It will exit with code 1 if:

  • flag does not exist
  • flag value has a different type

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...env.Option) *Builder

func (*Builder) BindFlag

func (b *Builder) BindFlag(f flagItem) *Builder

func (*Builder) Build

func (b *Builder) Build() *FlagSet

type FlagSet

type FlagSet struct {
	// contains filtered or unexported fields
}

func (*FlagSet) BindEnvVars

func (fs *FlagSet) BindEnvVars() error

BindEnvVars binds environment variables to the corresponding flags in the FlagSet. It constructs a VarNameConstructor using the provided characters 'charOld' and 'charNew' and the environment options in the FlagSet. For each flag in the FlagSet, it retrieves the value of the environment variable using the VarNameConstructor and calls the FromEnvVariable method of the flag. If an error occurs during parsing, it is joined with the previous errors using the errors.Join function. The function returns the error encountered during parsing, if any.

func (*FlagSet) Parse

func (fs *FlagSet) Parse(args []string) error

Parse iterates over the given args and calls the corresponding parse function for long flags and short flags. It returns an error if any parsing fails.

Jump to

Keyboard shortcuts

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