flags

package
v3.3.27+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 10 Imported by: 22

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(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(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 StringsFromFlagV2

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

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

Types

type DeprecatedFlag

type DeprecatedFlag struct {
	Name string
}

DeprecatedFlag encapsulates a flag that may have been previously valid but is now deprecated. If a DeprecatedFlag is set, an error occurs.

func (*DeprecatedFlag) Set

func (f *DeprecatedFlag) Set(_ string) error

func (*DeprecatedFlag) String

func (f *DeprecatedFlag) String() string

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 StringsFlag

type StringsFlag struct {
	Values []string
	// contains filtered or unexported fields
}

StringsFlag implements the flag.Value interface.

func NewStringsFlag

func NewStringsFlag(valids ...string) *StringsFlag

NewStringsFlag 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 (*StringsFlag) Set

func (ss *StringsFlag) Set(s string) error

Set verifies the argument to be a valid member of the allowed values before setting the underlying flag value.

func (*StringsFlag) String

func (ss *StringsFlag) String() string

String returns the set value (if any) of the StringsFlag

type StringsValueV2

type StringsValueV2 sort.StringSlice

StringsValueV2 wraps "sort.StringSlice".

func NewStringsValueV2

func NewStringsValueV2(s string) (ss *StringsValueV2)

NewStringsValueV2 implements string slice as "flag.Value" interface. Given value is to be separated by comma.

func (*StringsValueV2) Set

func (ss *StringsValueV2) Set(s string) error

Set parses a command line set of strings, separated by comma. Implements "flag.Value" interface.

func (*StringsValueV2) String

func (ss *StringsValueV2) String() string

String implements "flag.Value" interface.

type URLsValue

type URLsValue types.URLs

func NewURLsValue

func NewURLsValue(init string) *URLsValue

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

func (*URLsValue) String

func (us *URLsValue) String() string

Jump to

Keyboard shortcuts

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