flags

package
v0.0.0-...-518322d Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package flags implements command-line flag parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlagToEnv

func FlagToEnv(prefix, name string) string

FlagToEnv converts flag string to upper-case environment variable key string.

func IsSet

func IsSet(fs *flag.FlagSet, name string) bool

func SetFlagsFromEnv

func SetFlagsFromEnv(lg *zap.Logger, prefix string, fs *flag.FlagSet) error

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

func SetPflagsFromEnv(lg *zap.Logger, prefix string, fs *pflag.FlagSet) error

SetPflagsFromEnv is similar to SetFlagsFromEnv. However, the accepted flagset type is pflag.FlagSet and it does not do any logging.

func StringsFromFlag

func StringsFromFlag(fs *flag.FlagSet, flagName string) []string

StringsFromFlag returns a string slice from the flag.

func URLsFromFlag

func URLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL

URLsFromFlag returns a slices from url got from the flag.

func UniqueStringsFromFlag

func UniqueStringsFromFlag(fs *flag.FlagSet, flagName string) []string

UniqueStringsFromFlag returns a string slice from the flag.

func UniqueStringsMapFromFlag

func UniqueStringsMapFromFlag(fs *flag.FlagSet, flagName string) map[string]struct{}

UniqueStringsMapFromFlag returns a map of strings from the flag.

func UniqueURLsFromFlag

func UniqueURLsFromFlag(fs *flag.FlagSet, urlsFlagName string) []url.URL

UniqueURLsFromFlag returns a slice from urls got from the flag.

func UniqueURLsMapFromFlag

func UniqueURLsMapFromFlag(fs *flag.FlagSet, urlsFlagName string) map[string]struct{}

UniqueURLsMapFromFlag returns a map from url strings got from the flag.

Types

type IgnoredFlag

type IgnoredFlag struct {
	Name string
	// contains filtered or unexported fields
}

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

type URLsValue types.URLs

URLsValue wraps "types.URLs".

func NewURLsValue

func NewURLsValue(s string) *URLsValue

NewURLsValue implements "url.URL" slice as flag.Value interface. Given value is to be separated by comma.

func (*URLsValue) Set

func (us *URLsValue) 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 (*URLsValue) String

func (us *URLsValue) String() string

String 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.

Jump to

Keyboard shortcuts

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