Documentation
¶
Overview ¶
Package flagx provides enhanced command-line flag parsing capabilities beyond the standard 'flag' library, supporting struct tags, environment variables, configuration files, and key-value pairs.
Index ¶
- Variables
- func File[T any](v *T, name, short, def, usage string)
- func FileUnmarshal[T any](v *T, name, short, def, usage string, unmarshal func([]byte, any) error)
- func Init(fSet *FlagSet, name string)
- func IsNilSafe(v reflect.Value) bool
- func Name() string
- func Pair(v *[2]string, name, short string, def [][2]string, usage string)
- func Pairs(v *[][2]string, name, short string, def [][2]string, usage string)
- func Struct[T any](pStruct *T)
- func StructSet[T any](fset *FlagSet, pStruct *T, errExit bool) (err error)
- func Usage()
- func Var[T flagType](val *T, name, shorthand, usage string, env ...string)
- type FlagItem
- func FileSet[T any](fset *FlagSet, v *T, name, short, def, usage string) *FlagItem
- func FileUnmarshalSet[T any](fset *FlagSet, v *T, name, short, def, usage string, ...) *FlagItem
- func PairSet(fset *FlagSet, v *[2]string, name, short string, usage string) *FlagItem
- func PairsSet(fset *FlagSet, v *[][2]string, name, short string, usage string) *FlagItem
- func VarSet[T flagType](fset *FlagSet, val *T, name, shorthand, usage string, env ...string) (f *FlagItem, err error)
- type FlagSet
Constants ¶
This section is empty.
Variables ¶
var ( // Parse parses the command-line arguments. Parse = pflag.Parse // CommandLine is the default FlagSet that manages command-line flags. CommandLine = pflag.CommandLine )
var ( // Description holds the description of the application shown in help. Description = "" // Version holds the version of the application shown in help. Version = "" )
Functions ¶
func File ¶
File registers a flag that loads data from a file into the provided variable. The file content is parsed as JSON by default.
func FileUnmarshal ¶
FileUnmarshal registers a flag that loads data from a file and unmarshals it using the provided function.
func IsNilSafe ¶
IsNilSafe checks if a reflect.Value is nil.
Only pointers, slices, maps, channels, functions or interfaces can call IsNil. Returns false for other types.
func Pairs ¶
Pairs registers a flag that accepts multiple key-value pairs in the format "key:value".
func Struct ¶
func Struct[T any](pStruct *T)
Struct defines command-line flags from fields of a struct.
Types ¶
type FlagItem ¶
FlagItem represents a single flag item in the FlagSet.
func FileSet ¶
FileSet registers a flag that loads data from a file into the provided variable in the given FlagSet. The file content is parsed as JSON by default.
func FileUnmarshalSet ¶
func FileUnmarshalSet[T any](fset *FlagSet, v *T, name, short, def, usage string, unmarshal func([]byte, any) error) *FlagItem
FileUnmarshalSet registers a flag that loads data from a file and unmarshals it using the provided function in the given FlagSet.
func PairSet ¶
PairSet registers a flag that accepts a single key-value pair in the format "key:value" in the given FlagSet.