pflag

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 15 Imported by: 0

README

pflag — pflag compatibility layer

Drop-in replacement for spf13/pflag backed by OptArgs Core's POSIX/GNU getopt implementation.

Feature Comparison

Feature Upstream pflag pflag/ (compat)
String/Bool/Int/Float/Duration flags
Shorthand flags (-v)
StringSlice/IntSlice
StringArray
StringToString/StringToInt/StringToInt64
Count flags (-vvv)
Unknown flag errors
-- termination
FlagSet creation
PrintDefaults/FlagUsages
ContinueOnError/ExitOnError/PanicOnError
Lookup/Set/Changed
NFlag/NArg/Args
VisitAll/Visit
AddFlagSet
Deprecated/ShorthandDeprecated
Hidden flags
SortFlags
SetInterspersed
AddGoFlagSet
IP/IPMask/IPNet
TextVar
Typed getters (GetBool, GetInt, etc.)
POSIX short-option compaction (-abc)
Abbreviation matching (--verb → --verbose, ambiguity detection)
Arbitrary option names (=, :, [] in names)
Boolean negation (--no-flag) (spf13/pflag#214, spf13/cobra#958)
Boolean prefix pairs (--enable/--disable)
Short-only flags (no long name) (spf13/pflag#139, spf13/pflag#256)
Many-to-one flag mappings
BoolArgValuer (NoArg vs OptionalArg) (spf13/pflag#214)
getopt_long_only mode
Error message format ⚠️¹

¹ Inner error uses core's unified format instead of raw strconv errors. See compat/expected_diffs.go for all documented divergences. Every ✅ and ❌ is backed by a test — see compat/compat_test.go, pflag_test.go, and pflag_optargs_test.go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandLine = NewFlagSet(os.Args[0], ExitOnError)

CommandLine is the default set of command-line flags, parsed from os.Args.

View Source
var ErrHelp = errors.New("pflag: help requested")

ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.

Functions

func AddFlag

func AddFlag(f *Flag)

func AddFlagSet

func AddFlagSet(newSet *FlagSet)

func AddGoFlag

func AddGoFlag(goflag *flag.Flag)

func AddGoFlagSet

func AddGoFlagSet(goflags *flag.FlagSet)

func Arg

func Arg(i int) string

func Args

func Args() []string

func ArgsLenAtDash

func ArgsLenAtDash() int

func Bool

func Bool(name string, value bool, usage string) *bool

func BoolFunc

func BoolFunc(name, usage string, fn func(string) error)

func BoolFuncP

func BoolFuncP(name, sh, usage string, fn func(string) error)

func BoolP

func BoolP(name, sh string, value bool, usage string) *bool

func BoolSlice

func BoolSlice(name string, value []bool, usage string) *[]bool

func BoolSliceP

func BoolSliceP(name, sh string, value []bool, usage string) *[]bool

func BoolSliceVar

func BoolSliceVar(p *[]bool, name string, value []bool, usage string)

func BoolSliceVarP

func BoolSliceVarP(p *[]bool, name, sh string, value []bool, usage string)

func BoolVar

func BoolVar(p *bool, name string, value bool, usage string)

func BoolVarP

func BoolVarP(p *bool, name, sh string, value bool, usage string)

func BytesBase64

func BytesBase64(name string, value []byte, usage string) *[]byte

func BytesBase64P

func BytesBase64P(name, sh string, value []byte, usage string) *[]byte

func BytesBase64Var

func BytesBase64Var(p *[]byte, name string, value []byte, usage string)

func BytesBase64VarP

func BytesBase64VarP(p *[]byte, name, sh string, value []byte, usage string)

func BytesHex

func BytesHex(name string, value []byte, usage string) *[]byte

func BytesHexP

func BytesHexP(name, sh string, value []byte, usage string) *[]byte

func BytesHexVar

func BytesHexVar(p *[]byte, name string, value []byte, usage string)

func BytesHexVarP

func BytesHexVarP(p *[]byte, name, sh string, value []byte, usage string)

func Changed

func Changed(name string) bool

func CopyToGoFlagSet

func CopyToGoFlagSet(pfs *FlagSet, gofs *flag.FlagSet)

CopyToGoFlagSet copies all pflag flags to a Go stdlib FlagSet. Each flag is registered as a string flag using its current string value.

func Count

func Count(name, usage string) *int

func CountP

func CountP(name, sh, usage string) *int

func CountVar

func CountVar(p *int, name, usage string)

func CountVarP

func CountVarP(p *int, name, sh, usage string)

func Duration

func Duration(name string, value time.Duration, usage string) *time.Duration

func DurationP

func DurationP(name, sh string, value time.Duration, usage string) *time.Duration

func DurationSlice

func DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration

func DurationSliceP

func DurationSliceP(name, sh string, value []time.Duration, usage string) *[]time.Duration

func DurationSliceVar

func DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)

func DurationSliceVarP

func DurationSliceVarP(p *[]time.Duration, name, sh string, value []time.Duration, usage string)

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration, usage string)

func DurationVarP

func DurationVarP(p *time.Duration, name, sh string, value time.Duration, usage string)

func FlagUsages

func FlagUsages() string

func FlagUsagesWrapped

func FlagUsagesWrapped(cols int) string

func Float32

func Float32(name string, value float32, usage string) *float32

func Float32P

func Float32P(name, sh string, value float32, usage string) *float32

func Float32Slice

func Float32Slice(name string, value []float32, usage string) *[]float32

func Float32SliceP

func Float32SliceP(name, sh string, value []float32, usage string) *[]float32

func Float32SliceVar

func Float32SliceVar(p *[]float32, name string, value []float32, usage string)

func Float32SliceVarP

func Float32SliceVarP(p *[]float32, name, sh string, value []float32, usage string)

func Float32Var

func Float32Var(p *float32, name string, value float32, usage string)

func Float32VarP

func Float32VarP(p *float32, name, sh string, value float32, usage string)

func Float64

func Float64(name string, value float64, usage string) *float64

func Float64P

func Float64P(name, sh string, value float64, usage string) *float64

func Float64Slice

func Float64Slice(name string, value []float64, usage string) *[]float64

func Float64SliceP

func Float64SliceP(name, sh string, value []float64, usage string) *[]float64

func Float64SliceVar

func Float64SliceVar(p *[]float64, name string, value []float64, usage string)

func Float64SliceVarP

func Float64SliceVarP(p *[]float64, name, sh string, value []float64, usage string)

func Float64Var

func Float64Var(p *float64, name string, value float64, usage string)

func Float64VarP

func Float64VarP(p *float64, name, sh string, value float64, usage string)

func Func

func Func(name, usage string, fn func(string) error)

func FuncP

func FuncP(name, sh, usage string, fn func(string) error)

func HasAvailableFlags

func HasAvailableFlags() bool

func HasFlags

func HasFlags() bool

func IP

func IP(name string, value net.IP, usage string) *net.IP

func IPMask

func IPMask(name string, value net.IPMask, usage string) *net.IPMask

func IPMaskP

func IPMaskP(name, sh string, value net.IPMask, usage string) *net.IPMask

func IPMaskVar

func IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)

func IPMaskVarP

func IPMaskVarP(p *net.IPMask, name, sh string, value net.IPMask, usage string)

func IPNet

func IPNet(name string, value net.IPNet, usage string) *net.IPNet

func IPNetP

func IPNetP(name, sh string, value net.IPNet, usage string) *net.IPNet

func IPNetVar

func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)

func IPNetVarP

func IPNetVarP(p *net.IPNet, name, sh string, value net.IPNet, usage string)

func IPP

func IPP(name, sh string, value net.IP, usage string) *net.IP

func IPVar

func IPVar(p *net.IP, name string, value net.IP, usage string)

func IPVarP

func IPVarP(p *net.IP, name, sh string, value net.IP, usage string)

func Int

func Int(name string, value int, usage string) *int

func Int8

func Int8(name string, value int8, usage string) *int8

func Int8P

func Int8P(name, sh string, value int8, usage string) *int8

func Int8Var

func Int8Var(p *int8, name string, value int8, usage string)

func Int8VarP

func Int8VarP(p *int8, name, sh string, value int8, usage string)

func Int16

func Int16(name string, value int16, usage string) *int16

func Int16P

func Int16P(name, sh string, value int16, usage string) *int16

func Int16Var

func Int16Var(p *int16, name string, value int16, usage string)

func Int16VarP

func Int16VarP(p *int16, name, sh string, value int16, usage string)

func Int32

func Int32(name string, value int32, usage string) *int32

func Int32P

func Int32P(name, sh string, value int32, usage string) *int32

func Int32Slice

func Int32Slice(name string, value []int32, usage string) *[]int32

func Int32SliceP

func Int32SliceP(name, sh string, value []int32, usage string) *[]int32

func Int32SliceVar

func Int32SliceVar(p *[]int32, name string, value []int32, usage string)

func Int32SliceVarP

func Int32SliceVarP(p *[]int32, name, sh string, value []int32, usage string)

func Int32Var

func Int32Var(p *int32, name string, value int32, usage string)

func Int32VarP

func Int32VarP(p *int32, name, sh string, value int32, usage string)

func Int64

func Int64(name string, value int64, usage string) *int64

func Int64P

func Int64P(name, sh string, value int64, usage string) *int64

func Int64Slice

func Int64Slice(name string, value []int64, usage string) *[]int64

func Int64SliceP

func Int64SliceP(name, sh string, value []int64, usage string) *[]int64

func Int64SliceVar

func Int64SliceVar(p *[]int64, name string, value []int64, usage string)

func Int64SliceVarP

func Int64SliceVarP(p *[]int64, name, sh string, value []int64, usage string)

func Int64Var

func Int64Var(p *int64, name string, value int64, usage string)

func Int64VarP

func Int64VarP(p *int64, name, sh string, value int64, usage string)

func IntP

func IntP(name, sh string, value int, usage string) *int

func IntSlice

func IntSlice(name string, value []int, usage string) *[]int

func IntSliceP

func IntSliceP(name, sh string, value []int, usage string) *[]int

func IntSliceVar

func IntSliceVar(p *[]int, name string, value []int, usage string)

func IntSliceVarP

func IntSliceVarP(p *[]int, name, sh string, value []int, usage string)

func IntVar

func IntVar(p *int, name string, value int, usage string)

func IntVarP

func IntVarP(p *int, name, sh string, value int, usage string)

func MarkBoolPrefix

func MarkBoolPrefix(name, truePrefix, falsePrefix string) error

func MarkDeprecated

func MarkDeprecated(name, usageMessage string) error

func MarkHidden

func MarkHidden(name string) error

func MarkNegatable

func MarkNegatable(name string) error

func MarkShorthandDeprecated

func MarkShorthandDeprecated(name, usageMessage string) error

func NArg

func NArg() int

func NFlag

func NFlag() int

func Parse

func Parse()

func ParseAll

func ParseAll(args []string, fn func(*Flag, string) error) error

func ParseIPv4Mask

func ParseIPv4Mask(s string) (net.IPMask, error)

ParseIPv4Mask parses a dotted-quad string into a net.IPMask.

func Parsed

func Parsed() bool

func PrintDefaults

func PrintDefaults()

func Set

func Set(name, value string) error

func SetAnnotation

func SetAnnotation(name, key string, values []string) error

func SetInterspersed

func SetInterspersed(interspersed bool)

func SetNormalizeFunc

func SetNormalizeFunc(n func(*FlagSet, string) NormalizedName)

func String

func String(name, value, usage string) *string

func StringArray

func StringArray(name string, value []string, usage string) *[]string

func StringArrayP

func StringArrayP(name, sh string, value []string, usage string) *[]string

func StringArrayVar

func StringArrayVar(p *[]string, name string, value []string, usage string)

func StringArrayVarP

func StringArrayVarP(p *[]string, name, sh string, value []string, usage string)

func StringP

func StringP(name, sh, value, usage string) *string

func StringSlice

func StringSlice(name string, value []string, usage string) *[]string

func StringSliceP

func StringSliceP(name, sh string, value []string, usage string) *[]string

func StringSliceVar

func StringSliceVar(p *[]string, name string, value []string, usage string)

func StringSliceVarP

func StringSliceVarP(p *[]string, name, sh string, value []string, usage string)

func StringToInt

func StringToInt(name string, value map[string]int, usage string) *map[string]int

func StringToInt64

func StringToInt64(name string, value map[string]int64, usage string) *map[string]int64

func StringToInt64P

func StringToInt64P(name, sh string, value map[string]int64, usage string) *map[string]int64

func StringToInt64Var

func StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)

func StringToInt64VarP

func StringToInt64VarP(p *map[string]int64, name, sh string, value map[string]int64, usage string)

func StringToIntP

func StringToIntP(name, sh string, value map[string]int, usage string) *map[string]int

func StringToIntVar

func StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)

func StringToIntVarP

func StringToIntVarP(p *map[string]int, name, sh string, value map[string]int, usage string)

func StringToString

func StringToString(name string, value map[string]string, usage string) *map[string]string

func StringToStringP

func StringToStringP(name, sh string, value map[string]string, usage string) *map[string]string

func StringToStringVar

func StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)

func StringToStringVarP

func StringToStringVarP(p *map[string]string, name, sh string, value map[string]string, usage string)

func StringVar

func StringVar(p *string, name, value, usage string)

func StringVarP

func StringVarP(p *string, name, sh, value, usage string)

func TextVar

func TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string)

func TextVarP

func TextVarP(p encoding.TextUnmarshaler, name, sh string, value encoding.TextMarshaler, usage string)

func Uint

func Uint(name string, value uint, usage string) *uint

func Uint8

func Uint8(name string, value uint8, usage string) *uint8

func Uint8P

func Uint8P(name, sh string, value uint8, usage string) *uint8

func Uint8Var

func Uint8Var(p *uint8, name string, value uint8, usage string)

func Uint8VarP

func Uint8VarP(p *uint8, name, sh string, value uint8, usage string)

func Uint16

func Uint16(name string, value uint16, usage string) *uint16

func Uint16P

func Uint16P(name, sh string, value uint16, usage string) *uint16

func Uint16Var

func Uint16Var(p *uint16, name string, value uint16, usage string)

func Uint16VarP

func Uint16VarP(p *uint16, name, sh string, value uint16, usage string)

func Uint32

func Uint32(name string, value uint32, usage string) *uint32

func Uint32P

func Uint32P(name, sh string, value uint32, usage string) *uint32

func Uint32Var

func Uint32Var(p *uint32, name string, value uint32, usage string)

func Uint32VarP

func Uint32VarP(p *uint32, name, sh string, value uint32, usage string)

func Uint64

func Uint64(name string, value uint64, usage string) *uint64

func Uint64P

func Uint64P(name, sh string, value uint64, usage string) *uint64

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64, usage string)

func Uint64VarP

func Uint64VarP(p *uint64, name, sh string, value uint64, usage string)

func UintP

func UintP(name, sh string, value uint, usage string) *uint

func UintSlice

func UintSlice(name string, value []uint, usage string) *[]uint

func UintSliceP

func UintSliceP(name, sh string, value []uint, usage string) *[]uint

func UintSliceVar

func UintSliceVar(p *[]uint, name string, value []uint, usage string)

func UintSliceVarP

func UintSliceVarP(p *[]uint, name, sh string, value []uint, usage string)

func UintVar

func UintVar(p *uint, name string, value uint, usage string)

func UintVarP

func UintVarP(p *uint, name, sh string, value uint, usage string)

func UnquoteUsage

func UnquoteUsage(flag *Flag) (name string, usage string)

UnquoteUsage extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage. Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the flag's value, or the empty string if the flag is boolean.

func Usage

func Usage()

func Var

func Var(value Value, name, usage string)

func VarP

func VarP(value Value, name, sh, usage string)

func Visit

func Visit(fn func(*Flag))

func VisitAll

func VisitAll(fn func(*Flag))

Types

type ErrorHandling

type ErrorHandling int

ErrorHandling defines how FlagSet.Parse behaves if the parse fails.

const (
	// ContinueOnError will return an err from Parse() if an error is found.
	ContinueOnError ErrorHandling = iota
	// ExitOnError will call os.Exit(2) if an error is found when parsing.
	ExitOnError
	// PanicOnError will panic() if an error is found when parsing flags.
	PanicOnError
)

type Flag

type Flag struct {
	Name                string               // name as it appears on command line
	Shorthand           string               // one-letter abbreviated flag
	Usage               string               // help message
	Value               Value                // value as set
	DefValue            string               // default value (as text); for usage message
	Changed             bool                 // If the user set the value (or if left to default)
	NoOptDefVal         string               // default value (as text); if the flag is on the command line without any options
	Hidden              bool                 // used by cobra.Command to allow flags to be hidden from help/usage text
	Deprecated          string               // If this flag is deprecated, this string is the new or now thing to use
	ShorthandDeprecated string               // If the shorthand of this flag is deprecated, this string is the message
	Annotations         map[string][]string  // used by cobra.Command bash autocomple code
	Prefixes            []optargs.PrefixPair // registered boolean prefix pairs; nil when none
	Negatable           bool                 // non-boolean flag supports --no-<name> zero-clear
}

Flag represents the state of a flag.

func Lookup

func Lookup(name string) *Flag

func PFlagFromGoFlag

func PFlagFromGoFlag(goflag *flag.Flag) *Flag

PFlagFromGoFlag converts a Go stdlib flag.Flag to a pflag Flag.

func ShorthandLookup

func ShorthandLookup(name string) *Flag

func VarPF

func VarPF(value Value, name, sh, usage string) *Flag

type FlagSet

type FlagSet struct {
	// Usage is the function called when an error occurs while parsing flags.
	// The field is a function (not a method) that may be changed to point to
	// a custom error handler.
	Usage func()

	// SortFlags controls whether flags are sorted alphabetically in help text.
	// Default is true (matching upstream pflag).
	SortFlags bool

	// ParseErrorsAllowlist defines parsing errors that can be ignored.
	ParseErrorsAllowlist ParseErrorsAllowlist

	// ParseErrorsWhitelist defines parsing errors that can be ignored.
	//
	// Deprecated: use ParseErrorsAllowlist instead.
	ParseErrorsWhitelist ParseErrorsAllowlist
	// contains filtered or unexported fields
}

FlagSet represents a set of defined flags.

func NewFlagSet

func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet

NewFlagSet returns a new, empty flag set with the specified name and error handling property.

func (*FlagSet) AddFlag

func (f *FlagSet) AddFlag(flag *Flag)

AddFlag adds the flag to the FlagSet. If a flag with the same name already exists, the new flag is silently ignored (matching upstream pflag behavior).

func (*FlagSet) AddFlagSet

func (f *FlagSet) AddFlagSet(newSet *FlagSet)

AddFlagSet adds all flags from newSet to f. If a flag already exists in f, the flag from newSet is silently ignored.

func (*FlagSet) AddGoFlag

func (f *FlagSet) AddGoFlag(goflag *flag.Flag)

AddGoFlag adds a single Go stdlib flag to the FlagSet.

func (*FlagSet) AddGoFlagSet

func (f *FlagSet) AddGoFlagSet(goflags *flag.FlagSet)

AddGoFlagSet adds all flags from a Go stdlib FlagSet.

func (*FlagSet) AliasShortVar

func (f *FlagSet) AliasShortVar(value Value, shorthand string)

AliasShortVar registers a short-only alias that writes to the same Value. The alias is hidden from help text by default.

func (*FlagSet) AliasVar

func (f *FlagSet) AliasVar(value Value, name, usage string)

AliasVar registers an additional flag name that writes to the same Value as an existing flag. The alias flag is hidden from help text by default. This enables the ls --format=across / -x pattern where multiple flags share a destination with last-occurrence-wins semantics.

func (*FlagSet) AliasVarP

func (f *FlagSet) AliasVarP(value Value, name, shorthand, usage string)

AliasVarP is like AliasVar but accepts a shorthand.

func (*FlagSet) Arg

func (f *FlagSet) Arg(i int) string

Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed.

func (*FlagSet) Args

func (f *FlagSet) Args() []string

Args returns the non-flag arguments.

func (*FlagSet) ArgsLenAtDash

func (f *FlagSet) ArgsLenAtDash() int

ArgsLenAtDash returns the number of args before the -- terminator, or -1 if no -- was encountered.

func (*FlagSet) Bool

func (f *FlagSet) Bool(name string, value bool, usage string) *bool

Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.

func (*FlagSet) BoolFunc

func (f *FlagSet) BoolFunc(name string, usage string, fn func(string) error)

BoolFunc defines a boolean callback flag. The callback is called every time the flag is encountered. When used without a value (--flag), the callback receives an empty string. When used with a value (--flag=value), the callback receives the value.

func (*FlagSet) BoolFuncP

func (f *FlagSet) BoolFuncP(name, shorthand string, usage string, fn func(string) error)

BoolFuncP is like BoolFunc, but accepts a shorthand letter.

func (*FlagSet) BoolP

func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool

BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) BoolSlice

func (f *FlagSet) BoolSlice(name string, value []bool, usage string) *[]bool

func (*FlagSet) BoolSliceP

func (f *FlagSet) BoolSliceP(name, shorthand string, value []bool, usage string) *[]bool

func (*FlagSet) BoolSliceVar

func (f *FlagSet) BoolSliceVar(p *[]bool, name string, value []bool, usage string)

func (*FlagSet) BoolSliceVarP

func (f *FlagSet) BoolSliceVarP(p *[]bool, name, shorthand string, value []bool, usage string)

func (*FlagSet) BoolVar

func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)

BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func (*FlagSet) BoolVarP

func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string)

BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) BytesBase64

func (f *FlagSet) BytesBase64(name string, value []byte, usage string) *[]byte

func (*FlagSet) BytesBase64P

func (f *FlagSet) BytesBase64P(name, shorthand string, value []byte, usage string) *[]byte

func (*FlagSet) BytesBase64Var

func (f *FlagSet) BytesBase64Var(p *[]byte, name string, value []byte, usage string)

func (*FlagSet) BytesBase64VarP

func (f *FlagSet) BytesBase64VarP(p *[]byte, name, shorthand string, value []byte, usage string)

func (*FlagSet) BytesHex

func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte

func (*FlagSet) BytesHexP

func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte

func (*FlagSet) BytesHexVar

func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string)

func (*FlagSet) BytesHexVarP

func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string)

func (*FlagSet) Changed

func (f *FlagSet) Changed(name string) bool

Changed returns true if the named flag was set during Parse().

func (*FlagSet) Count

func (f *FlagSet) Count(name string, usage string) *int

func (*FlagSet) CountP

func (f *FlagSet) CountP(name, shorthand string, usage string) *int

func (*FlagSet) CountVar

func (f *FlagSet) CountVar(p *int, name string, usage string)

func (*FlagSet) CountVarP

func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string)

func (*FlagSet) Duration

func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration

Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.

func (*FlagSet) DurationP

func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration

DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) DurationSlice

func (f *FlagSet) DurationSlice(name string, value []time.Duration, usage string) *[]time.Duration

func (*FlagSet) DurationSliceP

func (f *FlagSet) DurationSliceP(name, shorthand string, value []time.Duration, usage string) *[]time.Duration

func (*FlagSet) DurationSliceVar

func (f *FlagSet) DurationSliceVar(p *[]time.Duration, name string, value []time.Duration, usage string)

func (*FlagSet) DurationSliceVarP

func (f *FlagSet) DurationSliceVarP(p *[]time.Duration, name, shorthand string, value []time.Duration, usage string)

func (*FlagSet) DurationVar

func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)

DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.

func (*FlagSet) DurationVarP

func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string)

DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) FlagUsages

func (f *FlagSet) FlagUsages() string

FlagUsages returns a string containing the usage information for all defined flags in the set. This is the same output as PrintDefaults but returned as a string instead of written to the output.

func (*FlagSet) FlagUsagesWrapped

func (f *FlagSet) FlagUsagesWrapped(cols int) string

FlagUsagesWrapped returns a string containing the usage information for all flags in the FlagSet. Wrapped to cols columns (0 for no wrapping).

func (*FlagSet) Float32

func (f *FlagSet) Float32(name string, value float32, usage string) *float32

func (*FlagSet) Float32P

func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32

func (*FlagSet) Float32Slice

func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32

func (*FlagSet) Float32SliceP

func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32

func (*FlagSet) Float32SliceVar

func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string)

func (*FlagSet) Float32SliceVarP

func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string)

func (*FlagSet) Float32Var

func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string)

func (*FlagSet) Float32VarP

func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string)

func (*FlagSet) Float64

func (f *FlagSet) Float64(name string, value float64, usage string) *float64

Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.

func (*FlagSet) Float64P

func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64

Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) Float64Slice

func (f *FlagSet) Float64Slice(name string, value []float64, usage string) *[]float64

func (*FlagSet) Float64SliceP

func (f *FlagSet) Float64SliceP(name, shorthand string, value []float64, usage string) *[]float64

func (*FlagSet) Float64SliceVar

func (f *FlagSet) Float64SliceVar(p *[]float64, name string, value []float64, usage string)

func (*FlagSet) Float64SliceVarP

func (f *FlagSet) Float64SliceVarP(p *[]float64, name, shorthand string, value []float64, usage string)

func (*FlagSet) Float64Var

func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)

Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.

func (*FlagSet) Float64VarP

func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string)

Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) Func

func (f *FlagSet) Func(name string, usage string, fn func(string) error)

Func defines a flag with the specified name and usage string. The callback function fn will be called every time the flag is encountered during parsing, with the flag's value as an argument.

func (*FlagSet) FuncP

func (f *FlagSet) FuncP(name, shorthand string, usage string, fn func(string) error)

FuncP is like Func, but accepts a shorthand letter.

func (*FlagSet) GetBool

func (f *FlagSet) GetBool(name string) (bool, error)

func (*FlagSet) GetBoolSlice

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

func (*FlagSet) GetBytesBase64

func (f *FlagSet) GetBytesBase64(name string) ([]byte, error)

GetBytesBase64 returns the []byte value of a flag with the given name.

func (*FlagSet) GetBytesHex

func (f *FlagSet) GetBytesHex(name string) ([]byte, error)

GetBytesHex returns the []byte value of a flag with the given name.

func (*FlagSet) GetCount

func (f *FlagSet) GetCount(name string) (int, error)

func (*FlagSet) GetDuration

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

func (*FlagSet) GetDurationSlice

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

func (*FlagSet) GetFloat32

func (f *FlagSet) GetFloat32(name string) (float32, error)

func (*FlagSet) GetFloat32Slice

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

func (*FlagSet) GetFloat64

func (f *FlagSet) GetFloat64(name string) (float64, error)

func (*FlagSet) GetFloat64Slice

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

func (*FlagSet) GetInt

func (f *FlagSet) GetInt(name string) (int, error)

func (*FlagSet) GetInt8

func (f *FlagSet) GetInt8(name string) (int8, error)

func (*FlagSet) GetInt16

func (f *FlagSet) GetInt16(name string) (int16, error)

func (*FlagSet) GetInt32

func (f *FlagSet) GetInt32(name string) (int32, error)

func (*FlagSet) GetInt32Slice

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

func (*FlagSet) GetInt64

func (f *FlagSet) GetInt64(name string) (int64, error)

func (*FlagSet) GetInt64Slice

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

func (*FlagSet) GetIntSlice

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

func (*FlagSet) GetInterspersed

func (f *FlagSet) GetInterspersed() bool

GetInterspersed returns whether interspersed option/non-option arguments are supported.

func (*FlagSet) GetNormalizeFunc

func (f *FlagSet) GetNormalizeFunc() func(f *FlagSet, name string) NormalizedName

GetNormalizeFunc returns the previously set NormalizeFunc, or nil if none was set.

func (*FlagSet) GetString

func (f *FlagSet) GetString(name string) (string, error)

func (*FlagSet) GetStringSlice

func (f *FlagSet) GetStringSlice(name string) ([]string, error)

func (*FlagSet) GetStringToInt

func (f *FlagSet) GetStringToInt(name string) (map[string]int, error)

func (*FlagSet) GetStringToInt64

func (f *FlagSet) GetStringToInt64(name string) (map[string]int64, error)

func (*FlagSet) GetStringToString

func (f *FlagSet) GetStringToString(name string) (map[string]string, error)

func (*FlagSet) GetUint

func (f *FlagSet) GetUint(name string) (uint, error)

func (*FlagSet) GetUint8

func (f *FlagSet) GetUint8(name string) (uint8, error)

func (*FlagSet) GetUint16

func (f *FlagSet) GetUint16(name string) (uint16, error)

func (*FlagSet) GetUint32

func (f *FlagSet) GetUint32(name string) (uint32, error)

func (*FlagSet) GetUint64

func (f *FlagSet) GetUint64(name string) (uint64, error)

func (*FlagSet) GetUintSlice

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

func (*FlagSet) HasAvailableFlags

func (f *FlagSet) HasAvailableFlags() bool

HasAvailableFlags returns true if the FlagSet has any non-hidden flags.

func (*FlagSet) HasFlags

func (f *FlagSet) HasFlags() bool

HasFlags returns true if the FlagSet has any flags defined.

func (*FlagSet) IP

func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP

func (*FlagSet) IPMask

func (f *FlagSet) IPMask(name string, value net.IPMask, usage string) *net.IPMask

func (*FlagSet) IPMaskP

func (f *FlagSet) IPMaskP(name, shorthand string, value net.IPMask, usage string) *net.IPMask

func (*FlagSet) IPMaskVar

func (f *FlagSet) IPMaskVar(p *net.IPMask, name string, value net.IPMask, usage string)

func (*FlagSet) IPMaskVarP

func (f *FlagSet) IPMaskVarP(p *net.IPMask, name, shorthand string, value net.IPMask, usage string)

func (*FlagSet) IPNet

func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet

func (*FlagSet) IPNetP

func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet

func (*FlagSet) IPNetVar

func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string)

func (*FlagSet) IPNetVarP

func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string)

func (*FlagSet) IPP

func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP

func (*FlagSet) IPVar

func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string)

func (*FlagSet) IPVarP

func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string)

func (*FlagSet) Init

func (f *FlagSet) Init(name string, errorHandling ErrorHandling)

Init sets the name and error handling property for a flag set.

func (*FlagSet) Int

func (f *FlagSet) Int(name string, value int, usage string) *int

Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.

func (*FlagSet) Int8

func (f *FlagSet) Int8(name string, value int8, usage string) *int8

func (*FlagSet) Int8P

func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8

func (*FlagSet) Int8Var

func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string)

func (*FlagSet) Int8VarP

func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string)

func (*FlagSet) Int16

func (f *FlagSet) Int16(name string, value int16, usage string) *int16

func (*FlagSet) Int16P

func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16

func (*FlagSet) Int16Var

func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string)

func (*FlagSet) Int16VarP

func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string)

func (*FlagSet) Int32

func (f *FlagSet) Int32(name string, value int32, usage string) *int32

func (*FlagSet) Int32P

func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32

func (*FlagSet) Int32Slice

func (f *FlagSet) Int32Slice(name string, value []int32, usage string) *[]int32

func (*FlagSet) Int32SliceP

func (f *FlagSet) Int32SliceP(name, shorthand string, value []int32, usage string) *[]int32

func (*FlagSet) Int32SliceVar

func (f *FlagSet) Int32SliceVar(p *[]int32, name string, value []int32, usage string)

func (*FlagSet) Int32SliceVarP

func (f *FlagSet) Int32SliceVarP(p *[]int32, name, shorthand string, value []int32, usage string)

func (*FlagSet) Int32Var

func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string)

func (*FlagSet) Int32VarP

func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string)

func (*FlagSet) Int64

func (f *FlagSet) Int64(name string, value int64, usage string) *int64

Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.

func (*FlagSet) Int64P

func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64

Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) Int64Slice

func (f *FlagSet) Int64Slice(name string, value []int64, usage string) *[]int64

func (*FlagSet) Int64SliceP

func (f *FlagSet) Int64SliceP(name, shorthand string, value []int64, usage string) *[]int64

func (*FlagSet) Int64SliceVar

func (f *FlagSet) Int64SliceVar(p *[]int64, name string, value []int64, usage string)

func (*FlagSet) Int64SliceVarP

func (f *FlagSet) Int64SliceVarP(p *[]int64, name, shorthand string, value []int64, usage string)

func (*FlagSet) Int64Var

func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)

Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.

func (*FlagSet) Int64VarP

func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string)

Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) IntP

func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int

IntP is like Int, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) IntSlice

func (f *FlagSet) IntSlice(name string, value []int, usage string) *[]int

IntSlice defines an int slice flag with specified name, default value, and usage string. The return value is the address of a []int variable that stores the value of the flag.

func (*FlagSet) IntSliceP

func (f *FlagSet) IntSliceP(name, shorthand string, value []int, usage string) *[]int

IntSliceP is like IntSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) IntSliceVar

func (f *FlagSet) IntSliceVar(p *[]int, name string, value []int, usage string)

IntSliceVar defines an int slice flag with specified name, default value, and usage string. The argument p points to a []int variable in which to store the value of the flag.

func (*FlagSet) IntSliceVarP

func (f *FlagSet) IntSliceVarP(p *[]int, name, shorthand string, value []int, usage string)

IntSliceVarP is like IntSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) IntVar

func (f *FlagSet) IntVar(p *int, name string, value int, usage string)

IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.

func (*FlagSet) IntVarP

func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string)

IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) LongOnly

func (f *FlagSet) LongOnly() bool

LongOnly returns whether getopt_long_only(3) mode is enabled.

func (*FlagSet) Lookup

func (f *FlagSet) Lookup(name string) *Flag

Lookup returns the Flag structure of the named flag, returning nil if none exists.

func (*FlagSet) MarkBoolPrefix

func (f *FlagSet) MarkBoolPrefix(name, truePrefix, falsePrefix string) error

MarkBoolPrefix registers a true/false prefix pair on a boolean flag. For example, MarkBoolPrefix("shared", "enable", "disable") registers --enable-shared (sets true) and --disable-shared (sets false). Multiple pairs may be registered on the same flag.

func (*FlagSet) MarkDeprecated

func (f *FlagSet) MarkDeprecated(name string, usageMessage string) error

MarkDeprecated indicates that a flag is deprecated. It will continue to function but will not show up in help or usage messages. Using this flag will also print the given usageMessage.

func (*FlagSet) MarkHidden

func (f *FlagSet) MarkHidden(name string) error

MarkHidden sets a flag to 'hidden' in your program. It will continue to function but will not show up in help or usage messages.

func (*FlagSet) MarkNegatable

func (f *FlagSet) MarkNegatable(name string) error

MarkNegatable marks a non-boolean flag as supporting --no-<name> to clear it to the type's zero value. Boolean flags are rejected since they already have automatic --no-<name>. Custom Value types without a known zero value are also rejected.

func (*FlagSet) MarkShorthandDeprecated

func (f *FlagSet) MarkShorthandDeprecated(name string, usageMessage string) error

MarkShorthandDeprecated will mark the shorthand of a flag deprecated. It will continue to function but will not show up in help or usage messages. Using the shorthand will also print the given usageMessage.

func (*FlagSet) NArg

func (f *FlagSet) NArg() int

NArg is the number of arguments remaining after flags have been processed.

func (*FlagSet) NFlag

func (f *FlagSet) NFlag() int

NFlag returns the number of flags that have been set.

func (*FlagSet) Name

func (f *FlagSet) Name() string

Name returns the name of the flag set.

func (*FlagSet) Output

func (f *FlagSet) Output() io.Writer

Output returns the destination for usage and error messages. os.Stderr is returned if output was not set or was set to nil.

func (*FlagSet) Parse

func (f *FlagSet) Parse(arguments []string) error

Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program.

ErrorHandling behavior on parse failure:

  • ContinueOnError: return the error
  • ExitOnError: print error + usage to output, call os.Exit(2)
  • PanicOnError: print error + usage to output, panic

func (*FlagSet) ParseAll

func (f *FlagSet) ParseAll(arguments []string, fn func(flag *Flag, value string) error) error

ParseAll parses flag definitions from the argument list and calls fn for each flag that is set. The arguments for fn are the flag and its value.

func (*FlagSet) Parsed

func (f *FlagSet) Parsed() bool

Parsed reports whether f.Parse has been called.

func (*FlagSet) PrintDefaults

func (f *FlagSet) PrintDefaults()

PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined flags in the set.

func (*FlagSet) Set

func (f *FlagSet) Set(name, value string) error

Set sets the value of the named flag.

func (*FlagSet) SetAnnotation

func (f *FlagSet) SetAnnotation(name, key string, values []string) error

SetAnnotation allows one to set arbitrary annotations on a flag in the FlagSet. This is sometimes used by spf13/cobra programs which want to generate additional bash completion information.

func (*FlagSet) SetInterspersed

func (f *FlagSet) SetInterspersed(interspersed bool)

SetInterspersed sets whether to support interspersed option/non-option arguments. When false, option processing stops at the first non-option argument (POSIX behavior).

func (*FlagSet) SetLongOnly

func (f *FlagSet) SetLongOnly(enabled bool)

SetLongOnly enables or disables getopt_long_only(3) behavior. When enabled, single-dash arguments (e.g., -verbose) are first tried as long options; on failure, the parser falls back to short option parsing.

func (*FlagSet) SetNormalizeFunc

func (f *FlagSet) SetNormalizeFunc(n func(f *FlagSet, name string) NormalizedName)

SetNormalizeFunc allows you to add a function which can translate flag names. Flags added to the FlagSet will be translated and then when anything tries to look up the flag that will also be translated. So it would be possible to create a flag named "getURL" and have it translated to "geturl". A user could then pass "--getUrl" which may also be translated to "geturl" and everything will work.

func (*FlagSet) SetOutput

func (f *FlagSet) SetOutput(output io.Writer)

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.

func (*FlagSet) ShortVar

func (f *FlagSet) ShortVar(value Value, shorthand, usage string)

ShortVar registers a short-only flag (no long name). The flag is accessible only via its single-character shorthand and participates in POSIX compaction.

func (*FlagSet) ShorthandLookup

func (f *FlagSet) ShorthandLookup(name string) *Flag

ShorthandLookup returns the Flag structure of the short handed flag, returning nil if none exists. It panics if len(name) > 1.

func (*FlagSet) String

func (f *FlagSet) String(name string, value string, usage string) *string

String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func (*FlagSet) StringArray

func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string

func (*FlagSet) StringArrayP

func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string

func (*FlagSet) StringArrayVar

func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string)

func (*FlagSet) StringArrayVarP

func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)

func (*FlagSet) StringP

func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string

StringP is like String, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) StringSlice

func (f *FlagSet) StringSlice(name string, value []string, usage string) *[]string

StringSlice defines a string slice flag with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the flag.

func (*FlagSet) StringSliceP

func (f *FlagSet) StringSliceP(name, shorthand string, value []string, usage string) *[]string

StringSliceP is like StringSlice, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) StringSliceVar

func (f *FlagSet) StringSliceVar(p *[]string, name string, value []string, usage string)

StringSliceVar defines a string slice flag with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the flag.

func (*FlagSet) StringSliceVarP

func (f *FlagSet) StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)

StringSliceVarP is like StringSliceVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) StringToInt

func (f *FlagSet) StringToInt(name string, value map[string]int, usage string) *map[string]int

func (*FlagSet) StringToInt64

func (f *FlagSet) StringToInt64(name string, value map[string]int64, usage string) *map[string]int64

func (*FlagSet) StringToInt64P

func (f *FlagSet) StringToInt64P(name, shorthand string, value map[string]int64, usage string) *map[string]int64

func (*FlagSet) StringToInt64Var

func (f *FlagSet) StringToInt64Var(p *map[string]int64, name string, value map[string]int64, usage string)

func (*FlagSet) StringToInt64VarP

func (f *FlagSet) StringToInt64VarP(p *map[string]int64, name, shorthand string, value map[string]int64, usage string)

func (*FlagSet) StringToIntP

func (f *FlagSet) StringToIntP(name, shorthand string, value map[string]int, usage string) *map[string]int

func (*FlagSet) StringToIntVar

func (f *FlagSet) StringToIntVar(p *map[string]int, name string, value map[string]int, usage string)

func (*FlagSet) StringToIntVarP

func (f *FlagSet) StringToIntVarP(p *map[string]int, name, shorthand string, value map[string]int, usage string)

func (*FlagSet) StringToString

func (f *FlagSet) StringToString(name string, value map[string]string, usage string) *map[string]string

func (*FlagSet) StringToStringP

func (f *FlagSet) StringToStringP(name, shorthand string, value map[string]string, usage string) *map[string]string

func (*FlagSet) StringToStringVar

func (f *FlagSet) StringToStringVar(p *map[string]string, name string, value map[string]string, usage string)

func (*FlagSet) StringToStringVarP

func (f *FlagSet) StringToStringVarP(p *map[string]string, name, shorthand string, value map[string]string, usage string)

func (*FlagSet) StringVar

func (f *FlagSet) StringVar(p *string, name string, value string, usage string)

StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func (*FlagSet) StringVarP

func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string)

StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) TextVar

func (f *FlagSet) TextVar(p encoding.TextUnmarshaler, name string, value encoding.TextMarshaler, usage string)

func (*FlagSet) TextVarP

func (f *FlagSet) TextVarP(p encoding.TextUnmarshaler, name, shorthand string, value encoding.TextMarshaler, usage string)

func (*FlagSet) Uint

func (f *FlagSet) Uint(name string, value uint, usage string) *uint

Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.

func (*FlagSet) Uint8

func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8

func (*FlagSet) Uint8P

func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8

func (*FlagSet) Uint8Var

func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string)

func (*FlagSet) Uint8VarP

func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string)

func (*FlagSet) Uint16

func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16

func (*FlagSet) Uint16P

func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16

func (*FlagSet) Uint16Var

func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string)

func (*FlagSet) Uint16VarP

func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string)

func (*FlagSet) Uint32

func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32

func (*FlagSet) Uint32P

func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32

func (*FlagSet) Uint32Var

func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string)

func (*FlagSet) Uint32VarP

func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string)

func (*FlagSet) Uint64

func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64

Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.

func (*FlagSet) Uint64P

func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64

Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) Uint64Var

func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)

Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.

func (*FlagSet) Uint64VarP

func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string)

Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) UintP

func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint

UintP is like Uint, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) UintSlice

func (f *FlagSet) UintSlice(name string, value []uint, usage string) *[]uint

func (*FlagSet) UintSliceP

func (f *FlagSet) UintSliceP(name, shorthand string, value []uint, usage string) *[]uint

func (*FlagSet) UintSliceVar

func (f *FlagSet) UintSliceVar(p *[]uint, name string, value []uint, usage string)

func (*FlagSet) UintSliceVarP

func (f *FlagSet) UintSliceVarP(p *[]uint, name, shorthand string, value []uint, usage string)

func (*FlagSet) UintVar

func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)

UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.

func (*FlagSet) UintVarP

func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string)

UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) Var

func (f *FlagSet) Var(value Value, name string, usage string)

Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func (*FlagSet) VarP

func (f *FlagSet) VarP(value Value, name, shorthand, usage string)

VarP is like Var, but accepts a shorthand letter that can be used after a single dash.

func (*FlagSet) VarPF

func (f *FlagSet) VarPF(value Value, name, shorthand, usage string) *Flag

VarPF is like VarP, but returns the flag created.

func (*FlagSet) Visit

func (f *FlagSet) Visit(fn func(*Flag))

Visit visits the flags in lexicographical order, calling fn for each. It visits only those flags that have been set.

func (*FlagSet) VisitAll

func (f *FlagSet) VisitAll(fn func(*Flag))

VisitAll visits the flags in lexicographical order, calling fn for each. It visits all flags, even those not set.

type Getter

type Getter interface {
	Value
	Get() any
}

Getter is the interface for flag values that can return their value as any. Identical to flag.Getter from the standard library.

type InvalidSyntaxError

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

InvalidSyntaxError is the error returned when a bad flag name is passed on the command line.

func (*InvalidSyntaxError) Error

func (e *InvalidSyntaxError) Error() string

func (*InvalidSyntaxError) GetSpecifiedFlag

func (e *InvalidSyntaxError) GetSpecifiedFlag() string

GetSpecifiedFlag returns the exact flag (with dashes) as it appeared in the parsed arguments.

type InvalidValueError

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

InvalidValueError is the error returned when an invalid value is used for a flag.

func (*InvalidValueError) Error

func (e *InvalidValueError) Error() string

func (*InvalidValueError) GetFlag

func (e *InvalidValueError) GetFlag() *Flag

GetFlag returns the flag for which the error occurred.

func (*InvalidValueError) GetValue

func (e *InvalidValueError) GetValue() string

GetValue returns the invalid value that was provided.

func (*InvalidValueError) Unwrap

func (e *InvalidValueError) Unwrap() error

Unwrap implements errors.Unwrap.

type NormalizedName

type NormalizedName string

NormalizedName is a flag name that has been normalized according to rules for the FlagSet (e.g. making '-' and '_' equivalent).

type NotExistError

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

NotExistError is the error returned when trying to access a flag that does not exist in the FlagSet.

func (*NotExistError) Error

func (e *NotExistError) Error() string

func (*NotExistError) GetSpecifiedName

func (e *NotExistError) GetSpecifiedName() string

GetSpecifiedName returns the name of the flag (without dashes) as it appeared in the parsed arguments.

func (*NotExistError) GetSpecifiedShortnames

func (e *NotExistError) GetSpecifiedShortnames() string

GetSpecifiedShortnames returns the group of shorthand arguments (without dashes) that the flag appeared within. Empty if not in a group.

type ParseErrorsAllowlist

type ParseErrorsAllowlist struct {
	// UnknownFlags will ignore unknown flags errors and continue parsing.
	UnknownFlags bool
}

ParseErrorsAllowlist defines the parsing errors that can be ignored.

type ParseErrorsWhitelist

type ParseErrorsWhitelist = ParseErrorsAllowlist

ParseErrorsWhitelist is a deprecated alias for ParseErrorsAllowlist. Retained for backward compatibility with spf13/pflag consumers.

type SliceValue

type SliceValue interface {
	Append(string) error
	Replace([]string) error
	GetSlice() []string
}

SliceValue is the interface for slice-typed flag values that support programmatic append, replace, and retrieval operations.

type Value

type Value interface {
	String() string
	Set(string) error
	Type() string
}

Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.)

type ValueRequiredError

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

ValueRequiredError is the error returned when a flag needs an argument but no argument was provided.

func (*ValueRequiredError) Error

func (e *ValueRequiredError) Error() string

func (*ValueRequiredError) GetFlag

func (e *ValueRequiredError) GetFlag() *Flag

GetFlag returns the flag for which the error occurred.

func (*ValueRequiredError) GetSpecifiedName

func (e *ValueRequiredError) GetSpecifiedName() string

GetSpecifiedName returns the name of the flag as it appeared in the arguments.

func (*ValueRequiredError) GetSpecifiedShortnames

func (e *ValueRequiredError) GetSpecifiedShortnames() string

GetSpecifiedShortnames returns the shorthand group, or empty string.

Jump to

Keyboard shortcuts

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