Documentation ¶
Overview ¶
Package flags implements command-line flag parsing.
Index ¶
- func FlagToEnv(prefix, name string) string
- func IsSet(fs *flag.FlagSet, name string) bool
- func SetFlagsFromEnv(prefix string, fs *flag.FlagSet) error
- func SetPflagsFromEnv(prefix string, fs *pflag.FlagSet) error
- func StringsFromFlag(fs *flag.FlagSet, flagName string) []string
- func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL
- func UniqueStringsFromFlag(fs *flag.FlagSet, flagName string) []string
- func UniqueStringsMapFromFlag(fs *flag.FlagSet, flagName string) map[string]struct{}
- func UniqueURLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL
- func UniqueURLsMapFromFlag(fs *flag.FlagSet, urlsFlagName string) map[string]struct{}
- type IgnoredFlag
- type SelectiveStringValue
- type SelectiveStringsValue
- type StringsValue
- type URLsValue
- type UniqueStringsValue
- type UniqueURLs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetFlagsFromEnv ¶
SetFlagsFromEnv parses all registered flags in the given flagset, and if they are not already set it attempts to set their values from environment variables. Environment variables take the name of the flag but are UPPERCASE, have the given prefix and any dashes are replaced by underscores - for example: some-flag => ETCD_SOME_FLAG
func SetPflagsFromEnv ¶
SetPflagsFromEnv is similar to SetFlagsFromEnv. However, the accepted flagset type is pflag.FlagSet and it does not do any logging.
func StringsFromFlag ¶
StringsFromFlag returns a string slice from the flag.
func URLsFromFlag ¶
URLsFromFlag returns a slices from url got from the flag.
func UniqueStringsFromFlag ¶
UniqueStringsFromFlag returns a string slice from the flag.
func UniqueStringsMapFromFlag ¶
UniqueStringsMapFromFlag returns a map of strings from the flag.
func UniqueURLsFromFlag ¶
UniqueURLsFromFlag returns a slice from urls got from the flag.
Types ¶
type IgnoredFlag ¶
type IgnoredFlag struct {
Name string
}
IgnoredFlag encapsulates a flag that may have been previously valid but is now ignored. If an IgnoredFlag is set, a warning is printed and operation continues.
func (*IgnoredFlag) IsBoolFlag ¶
func (f *IgnoredFlag) IsBoolFlag() bool
IsBoolFlag is defined to allow the flag to be defined without an argument
func (*IgnoredFlag) Set ¶
func (f *IgnoredFlag) Set(s string) error
func (*IgnoredFlag) String ¶
func (f *IgnoredFlag) String() string
type SelectiveStringValue ¶
type SelectiveStringValue struct {
// contains filtered or unexported fields
}
SelectiveStringValue implements the flag.Value interface.
func NewSelectiveStringValue ¶
func NewSelectiveStringValue(valids ...string) *SelectiveStringValue
NewSelectiveStringValue creates a new string flag for which any one of the given strings is a valid value, and any other value is an error.
valids[0] will be default value. Caller must be sure len(valids) != 0 or it will panic.
func (*SelectiveStringValue) Set ¶
func (ss *SelectiveStringValue) Set(s string) error
Set verifies the argument to be a valid member of the allowed values before setting the underlying flag value.
func (*SelectiveStringValue) String ¶
func (ss *SelectiveStringValue) String() string
String returns the set value (if any) of the SelectiveStringValue
func (*SelectiveStringValue) Valids ¶
func (ss *SelectiveStringValue) Valids() []string
Valids returns the list of valid strings.
type SelectiveStringsValue ¶
type SelectiveStringsValue struct {
// contains filtered or unexported fields
}
SelectiveStringsValue implements the flag.Value interface.
func NewSelectiveStringsValue ¶
func NewSelectiveStringsValue(valids ...string) *SelectiveStringsValue
NewSelectiveStringsValue creates a new string slice flag for which any one of the given strings is a valid value, and any other value is an error.
func (*SelectiveStringsValue) Set ¶
func (ss *SelectiveStringsValue) Set(s string) error
Set verifies the argument to be a valid member of the allowed values before setting the underlying flag value.
func (*SelectiveStringsValue) String ¶
func (ss *SelectiveStringsValue) String() string
String returns the set value (if any) of the SelectiveStringsValue.
func (*SelectiveStringsValue) Valids ¶
func (ss *SelectiveStringsValue) Valids() []string
Valids returns the list of valid strings.
type StringsValue ¶
type StringsValue sort.StringSlice
StringsValue wraps "sort.StringSlice".
func NewStringsValue ¶
func NewStringsValue(s string) (ss *StringsValue)
NewStringsValue implements string slice as "flag.Value" interface. Given value is to be separated by comma.
func (*StringsValue) Set ¶
func (ss *StringsValue) Set(s string) error
Set parses a command line set of strings, separated by comma. Implements "flag.Value" interface.
func (*StringsValue) String ¶
func (ss *StringsValue) String() string
String implements "flag.Value" interface.
type URLsValue ¶
URLsValue wraps "types.URLs".
func NewURLsValue ¶
NewURLsValue implements "url.URL" slice as flag.Value interface. Given value is to be separated by comma.
func (*URLsValue) Set ¶
Set parses a command line set of URLs formatted like: http://127.0.0.1:2380,http://10.1.1.2:80 Implements "flag.Value" interface.
type UniqueStringsValue ¶
type UniqueStringsValue struct {
Values map[string]struct{}
}
UniqueStringsValue wraps a list of unique strings. The values are set in order.
func NewUniqueStringsValue ¶
func NewUniqueStringsValue(s string) (us *UniqueStringsValue)
NewUniqueStringsValue implements string slice as "flag.Value" interface. Given value is to be separated by comma. The values are set in order.
func (*UniqueStringsValue) Set ¶
func (us *UniqueStringsValue) Set(s string) error
Set parses a command line set of strings, separated by comma. Implements "flag.Value" interface. The values are set in order.
func (*UniqueStringsValue) String ¶
func (us *UniqueStringsValue) String() string
String implements "flag.Value" interface.
type UniqueURLs ¶
type UniqueURLs struct { Values map[string]struct{} Allowed map[string]struct{} // contains filtered or unexported fields }
UniqueURLs contains unique URLs with non-URL exceptions.
func NewUniqueURLsWithExceptions ¶
func NewUniqueURLsWithExceptions(s string, exceptions ...string) *UniqueURLs
NewUniqueURLsWithExceptions implements "url.URL" slice as flag.Value interface. Given value is to be separated by comma.
func (*UniqueURLs) Set ¶
func (us *UniqueURLs) Set(s string) error
Set parses a command line set of URLs formatted like: http://127.0.0.1:2380,http://10.1.1.2:80 Implements "flag.Value" interface.
func (*UniqueURLs) String ¶
func (us *UniqueURLs) String() string
String implements "flag.Value" interface.