Documentation ¶
Index ¶
- Variables
- func ToString(slice []string) string
- func ToStringSlice(value string, options Options) ([]string, error)
- type AllowdTypes
- type CallBackFunc
- type EnumVar
- type EnumVariable
- type FlagData
- type FlagSet
- func (flagSet *FlagSet) BoolVar(field *bool, long string, defaultValue bool, usage string) *FlagData
- func (flagSet *FlagSet) BoolVarP(field *bool, long, short string, defaultValue bool, usage string) *FlagData
- func (flagSet *FlagSet) CallbackVar(callback CallBackFunc, long string, usage string) *FlagData
- func (flagSet *FlagSet) CallbackVarP(callback CallBackFunc, long, short string, usage string) *FlagData
- func (flagSet *FlagSet) CreateGroup(groupName, description string, flags ...*FlagData)
- func (flagSet *FlagSet) DurationVar(field *time.Duration, long string, defaultValue time.Duration, usage string) *FlagData
- func (flagSet *FlagSet) DurationVarP(field *time.Duration, long, short string, defaultValue time.Duration, ...) *FlagData
- func (flagSet *FlagSet) EnumVar(field *string, long string, defaultValue EnumVariable, usage string, ...) *FlagData
- func (flagSet *FlagSet) EnumVarP(field *string, long, short string, defaultValue EnumVariable, usage string, ...) *FlagData
- func (flagSet *FlagSet) GetConfigFilePath() (string, error)
- func (flagset *FlagSet) GetToolConfigDir() string
- func (flagSet *FlagSet) IntVar(field *int, long string, defaultValue int, usage string) *FlagData
- func (flagSet *FlagSet) IntVarP(field *int, long, short string, defaultValue int, usage string) *FlagData
- func (flagSet *FlagSet) MergeConfigFile(file string) error
- func (flagSet *FlagSet) Parse() error
- func (flagSet *FlagSet) PortVar(field *Port, long string, defaultValue []string, usage string) *FlagData
- func (flagSet *FlagSet) PortVarP(field *Port, long, short string, defaultValue []string, usage string) *FlagData
- func (flagSet *FlagSet) RuntimeMapVar(field *RuntimeMap, long string, defaultValue []string, usage string) *FlagData
- func (flagSet *FlagSet) RuntimeMapVarP(field *RuntimeMap, long, short string, defaultValue []string, usage string) *FlagData
- func (flagSet *FlagSet) SetConfigFilePath(filePath string)
- func (flagSet *FlagSet) SetDescription(description string)
- func (flagSet *FlagSet) SetGroup(name, description string)
- func (flagSet *FlagSet) SizeVar(field *Size, long string, defaultValue string, usage string) *FlagData
- func (flagSet *FlagSet) SizeVarP(field *Size, long, short string, defaultValue string, usage string) *FlagData
- func (flagSet *FlagSet) StringSliceVar(field *StringSlice, long string, defaultValue []string, usage string, ...) *FlagData
- func (flagSet *FlagSet) StringSliceVarConfigOnly(field *StringSlice, long string, defaultValue []string, usage string) *FlagData
- func (flagSet *FlagSet) StringSliceVarP(field *StringSlice, long, short string, defaultValue StringSlice, usage string, ...) *FlagData
- func (flagSet *FlagSet) StringVar(field *string, long, defaultValue, usage string) *FlagData
- func (flagSet *FlagSet) StringVarEnv(field *string, long, short, defaultValue, envName, usage string) *FlagData
- func (flagSet *FlagSet) StringVarP(field *string, long, short, defaultValue, usage string) *FlagData
- func (flagSet *FlagSet) Var(field flag.Value, long, usage string) *FlagData
- func (flagSet *FlagSet) VarP(field flag.Value, long, short, usage string) *FlagData
- type InsertionOrderedMap
- type Options
- type Port
- type RuntimeMap
- type Size
- type StringSlice
Constants ¶
This section is empty.
Variables ¶
var CommaSeparatedStringSliceOptions = Options{
IsEmpty: isEmpty,
}
CommaSeparatedStringSliceOptions represents a list of comma separated items Tokenization: Comma Normalization: None Type: []string Example: -flag value1,value2 => {"value1", "value2"}
var FileCommaSeparatedStringSliceOptions = Options{
IsEmpty: isEmpty,
IsFromFile: isFromFile,
}
FileCommaSeparatedStringSliceOptions represents a list of comma separated files containing items Tokenization: Comma Normalization: None Type: []string test.txt content: value1 value2
Example: -flag test.txt => {"value1", "value2"}
var FileNormalizedOriginalStringSliceOptions = Options{
IsEmpty: isEmpty,
Normalize: normalize,
IsFromFile: isFromFile,
}
FileNormalizedOriginalStringSliceOptions represents a list of items stored in a file Tokenization: Comma Normalization: Standard
var FileNormalizedStringSliceOptions = Options{
IsEmpty: isEmpty,
Normalize: normalizeLowercase,
IsFromFile: isFromFile,
}
FileNormalizedStringSliceOptions represents a list of path items Tokenization: Comma Normalization: Standard Type: []string Example: -flag /value/1 -flag value2 => {"/value/1", "value2"}
var FileStringSliceOptions = Options{ IsEmpty: isEmpty, Normalize: normalizeTrailingParts, IsFromFile: isFromFile, IsRaw: func(s string) bool { return true }, }
FileStringSliceOptions represents a list of items stored in a file Tokenization: Standard Normalization: Standard
var NormalizedOriginalStringSliceOptions = Options{
IsEmpty: isEmpty,
Normalize: normalize,
}
NormalizedOriginalStringSliceOptions represents a list of items Tokenization: None Normalization: Standard Type: []string Example: -flag /value/1 -flag 'value2' => {"/value/1", "value2"}
var NormalizedStringSliceOptions = Options{
IsEmpty: isEmpty,
Normalize: normalizeLowercase,
}
NormalizedStringSliceOptions represents a list of items Tokenization: Comma Normalization: Standard
var StringSliceOptions = Options{}
StringSliceOptions represents the default string slice (list of items) Tokenization: None Normalization: None Type: []string Example: -flag value1 -flag value2 => {"value1", "value2"}
Functions ¶
Types ¶
type AllowdTypes ¶
type AllowdTypes map[string]EnumVariable
func (AllowdTypes) String ¶
func (a AllowdTypes) String() string
type EnumVariable ¶
type EnumVariable int8
func (*EnumVariable) String ¶
func (e *EnumVariable) String() string
type FlagData ¶
type FlagData struct {
// contains filtered or unexported fields
}
type FlagSet ¶
type FlagSet struct { CaseSensitive bool Marshal bool CommandLine *flag.FlagSet // OtherOptionsGroupName is the name for all flags not in a group OtherOptionsGroupName string // contains filtered or unexported fields }
FlagSet is a list of flags for an application
func NewFlagSet ¶
func NewFlagSet() *FlagSet
NewFlagSet creates a new flagSet structure for the application
func (*FlagSet) BoolVar ¶
func (flagSet *FlagSet) BoolVar(field *bool, long string, defaultValue bool, usage string) *FlagData
BoolVar adds a bool flag with a longname
func (*FlagSet) BoolVarP ¶
func (flagSet *FlagSet) BoolVarP(field *bool, long, short string, defaultValue bool, usage string) *FlagData
BoolVarP adds a bool flag with a shortname and longname
func (*FlagSet) CallbackVar ¶
func (flagSet *FlagSet) CallbackVar(callback CallBackFunc, long string, usage string) *FlagData
CallbackVar adds a Callback flag with a longname
func (*FlagSet) CallbackVarP ¶
func (flagSet *FlagSet) CallbackVarP(callback CallBackFunc, long, short string, usage string) *FlagData
CallbackVarP adds a Callback flag with a shortname and longname
func (*FlagSet) CreateGroup ¶
CreateGroup within the flagset
func (*FlagSet) DurationVar ¶
func (flagSet *FlagSet) DurationVar(field *time.Duration, long string, defaultValue time.Duration, usage string) *FlagData
DurationVar adds a duration flag with a longname
func (*FlagSet) DurationVarP ¶
func (flagSet *FlagSet) DurationVarP(field *time.Duration, long, short string, defaultValue time.Duration, usage string) *FlagData
DurationVarP adds a duration flag with a short name and long name. It is equivalent to DurationVar but also allows specifying durations in days (e.g., "2d" for 2 days, which is equivalent to 2*24h). The default unit for durations is seconds (ex: "10" => 10s).
func (*FlagSet) EnumVar ¶
func (flagSet *FlagSet) EnumVar(field *string, long string, defaultValue EnumVariable, usage string, allowedTypes AllowdTypes) *FlagData
EnumVar adds a enum flag with a longname
func (*FlagSet) EnumVarP ¶
func (flagSet *FlagSet) EnumVarP(field *string, long, short string, defaultValue EnumVariable, usage string, allowedTypes AllowdTypes) *FlagData
EnumVarP adds a enum flag with a shortname and longname
func (*FlagSet) GetConfigFilePath ¶
GetConfigFilePath returns the config file path
func (*FlagSet) GetToolConfigDir ¶
GetToolConfigDir returns the config dir path of the tool
func (*FlagSet) IntVarP ¶
func (flagSet *FlagSet) IntVarP(field *int, long, short string, defaultValue int, usage string) *FlagData
IntVarP adds a int flag with a shortname and longname
func (*FlagSet) MergeConfigFile ¶
MergeConfigFile reads a config file to merge values from.
func (*FlagSet) PortVar ¶
func (flagSet *FlagSet) PortVar(field *Port, long string, defaultValue []string, usage string) *FlagData
PortVar adds a port flag with a longname
func (*FlagSet) PortVarP ¶
func (flagSet *FlagSet) PortVarP(field *Port, long, short string, defaultValue []string, usage string) *FlagData
PortVarP adds a port flag with a shortname and longname
func (*FlagSet) RuntimeMapVar ¶
func (flagSet *FlagSet) RuntimeMapVar(field *RuntimeMap, long string, defaultValue []string, usage string) *FlagData
RuntimeMapVarP adds a runtime only map flag with a longname
func (*FlagSet) RuntimeMapVarP ¶
func (flagSet *FlagSet) RuntimeMapVarP(field *RuntimeMap, long, short string, defaultValue []string, usage string) *FlagData
RuntimeMapVarP adds a runtime only map flag with a shortname and longname
func (*FlagSet) SetConfigFilePath ¶
SetConfigFilePath sets custom config file path
func (*FlagSet) SetDescription ¶
SetDescription sets the description field for a flagSet to a value.
func (*FlagSet) SetGroup ¶
SetGroup sets a group with name and description for the command line options
The order in which groups are passed is also kept as is, similar to flags.
func (*FlagSet) SizeVar ¶
func (flagSet *FlagSet) SizeVar(field *Size, long string, defaultValue string, usage string) *FlagData
SizeVar converts the given fileSize with a unit (kb, mb, gb, or tb) to bytes. For example, '2kb' will be converted to 2048. If no unit is provided, it will fallback to mb. e.g: '2' will be converted to 2097152.
func (*FlagSet) SizeVarP ¶
func (flagSet *FlagSet) SizeVarP(field *Size, long, short string, defaultValue string, usage string) *FlagData
SizeVarP converts the given fileSize with a unit (kb, mb, gb, or tb) to bytes. For example, '2kb' will be converted to 2048. If no unit is provided, it will fallback to mb. e.g: '2' will be converted to 2097152.
func (*FlagSet) StringSliceVar ¶
func (flagSet *FlagSet) StringSliceVar(field *StringSlice, long string, defaultValue []string, usage string, options Options) *FlagData
StringSliceVar adds a string slice flag with a longname Supports ONE value at a time. Adding multiple values require repeating the argument (-flag value1 -flag value2) No value normalization is happening.
func (*FlagSet) StringSliceVarConfigOnly ¶
func (flagSet *FlagSet) StringSliceVarConfigOnly(field *StringSlice, long string, defaultValue []string, usage string) *FlagData
StringSliceVarConfigOnly adds a string slice config value (without flag) with a longname
func (*FlagSet) StringSliceVarP ¶
func (flagSet *FlagSet) StringSliceVarP(field *StringSlice, long, short string, defaultValue StringSlice, usage string, options Options) *FlagData
StringSliceVarP adds a string slice flag with a shortname and longname Use options to customize the behavior
func (*FlagSet) StringVarEnv ¶
func (flagSet *FlagSet) StringVarEnv(field *string, long, short, defaultValue, envName, usage string) *FlagData
StringVarEnv adds a string flag with a shortname and longname with a default value read from env variable with a default value fallback
func (*FlagSet) StringVarP ¶
func (flagSet *FlagSet) StringVarP(field *string, long, short, defaultValue, usage string) *FlagData
StringVarP adds a string flag with a shortname and longname
type InsertionOrderedMap ¶
type InsertionOrderedMap struct {
// contains filtered or unexported fields
}
func (*InsertionOrderedMap) Set ¶
func (insertionOrderedMap *InsertionOrderedMap) Set(key string, value *FlagData)
type Options ¶
type Options struct { // IsFromFile determines if the values are from file IsFromFile func(string) bool // IsEmpty determines if the values are empty IsEmpty func(string) bool // Normalize the value (eg. removing trailing spaces) Normalize func(string) string // IsRaw determines if the value should be considered as a raw string IsRaw func(string) bool }
type Port ¶
type Port struct {
// contains filtered or unexported fields
}
Port is a list of unique ports in a normalized format
type RuntimeMap ¶
type RuntimeMap struct {
// contains filtered or unexported fields
}
RuntimeMap is a runtime only map of interfaces
func (*RuntimeMap) AsMap ¶
func (runtimeMap *RuntimeMap) AsMap() map[string]interface{}
AsMap returns the internal map as reference - changes are allowed
func (*RuntimeMap) Del ¶
func (runtimeMap *RuntimeMap) Del(key string) error
Del removes the specified key
func (*RuntimeMap) IsEmpty ¶
func (runtimeMap *RuntimeMap) IsEmpty() bool
IsEmpty specifies if the underlying map is empty
func (*RuntimeMap) Set ¶
func (runtimeMap *RuntimeMap) Set(value string) error
Set inserts a value to the map. Format: key=value
func (RuntimeMap) String ¶
func (runtimeMap RuntimeMap) String() string
type StringSlice ¶
type StringSlice []string
StringSlice is a slice of strings
func (*StringSlice) Set ¶
func (stringSlice *StringSlice) Set(value string) error
Set appends a value to the string slice.
func (StringSlice) String ¶
func (stringSlice StringSlice) String() string