flag

package
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBoolFlag

func GetBoolFlag(cmd *cobra.Command, flagName string, fatalIfMissing bool) bool

GetBoolFlag returns the value of the specified flag from a cobra command. If the flag is not specified and fatalIfMissing is true, this function logs a fatal error and calls os.Exit(255).

func GetOptionalBoolFlag

func GetOptionalBoolFlag(cmd *cobra.Command, flagName string) bool

GetOptionalBoolFlag returns the value of the specified flag from a cobra command, or the zero value (false) if the flag was not specified.

func GetOptionalStringArrayFlag

func GetOptionalStringArrayFlag(cmd *cobra.Command, flagName string) []string

GetOptionalStringArrayFlag returns the value of the specified flag from a cobra command, or the zero value if the flag was not specified.

func GetOptionalStringFlag

func GetOptionalStringFlag(cmd *cobra.Command, flagName string) string

GetOptionalStringFlag returns the value of the specified flag from a cobra command, or the zero value ("") if the flag was not specified.

func GetStringArrayFlag

func GetStringArrayFlag(cmd *cobra.Command, flagName string, fatalIfMissing bool) []string

GetStringArrayFlag returns the value of the specified flag from a cobra command. If the flag is not specified and fatalIfMissing is true, this function logs a fatal error and calls os.Exit(255).

func GetStringFlag

func GetStringFlag(cmd *cobra.Command, flagName string, fatalIfMissing bool) string

GetStringFlag returns the value of the specified flag from a cobra command. If the flag is not specified and fatalIfMissing is true, this function logs a fatal error and calls os.Exit(255).

Types

type Enum added in v0.4.0

type Enum struct {
	// contains filtered or unexported fields
}

Enum is a Cobra-compatible wrapper for defining a string flag that can be one of a specified set of values.

func NewEnum added in v0.4.0

func NewEnum(defaultValue string, allowedValues ...string) *Enum

NewEnum returns a new enum flag with the specified list of allowed values, and the specified default value if none is set.

func (*Enum) AllowedValues added in v0.9.0

func (e *Enum) AllowedValues() []string

AllowedValues returns a slice of the flag's valid values.

func (*Enum) Set added in v0.4.0

func (e *Enum) Set(s string) error

Set assigns the provided string to the enum receiver. It returns an error if the string is not an allowed value.

func (*Enum) String added in v0.4.0

func (e *Enum) String() string

String returns a string representation of the enum flag.

func (*Enum) Type added in v0.4.0

func (e *Enum) Type() string

Type returns a string representation of the Enum type.

type LabelSelector

type LabelSelector struct {
	LabelSelector *metav1.LabelSelector
}

LabelSelector is a Cobra-compatible wrapper for defining a Kubernetes label-selector flag.

func (*LabelSelector) Set

func (ls *LabelSelector) Set(s string) error

Set parses the provided string and assigns the result to the label-selector receiver. It returns an error if the string is not parseable.

func (*LabelSelector) String

func (ls *LabelSelector) String() string

String returns a string representation of the label selector flag.

func (*LabelSelector) Type

func (ls *LabelSelector) Type() string

Type returns a string representation of the LabelSelector type.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is a Cobra-compatible wrapper for defining a flag containing map data (i.e. a collection of key-value pairs).

func NewMap

func NewMap() Map

NewMap returns a Map using the default delimiters ("=" between keys and values, and "," between map entries, e.g. k1=v1,k2=v2)

func (*Map) Data

func (m *Map) Data() map[string]string

Data returns the underlying golang map storing the flag data.

func (*Map) Set

func (m *Map) Set(s string) error

Set parses the provided string according to the delimiters and assigns the result to the Map receiver. It returns an error if the string is not parseable.

func (*Map) String

func (m *Map) String() string

String returns a string representation of the Map flag.

func (*Map) Type

func (m *Map) Type() string

Type returns a string representation of the Map type.

func (Map) WithEntryDelimiter

func (m Map) WithEntryDelimiter(delimiter string) Map

WithEntryDelimiter sets the delimiter to be used between map entries.

For example, in "k1=v1&k2=v2", the entry delimiter is "&"

func (Map) WithKeyValueDelimiter

func (m Map) WithKeyValueDelimiter(delimiter string) Map

WithKeyValueDelimiter sets the delimiter to be used between keys and values.

For example, in "k1=v1&k2=v2", the key-value delimiter is "="

type OptionalBool added in v0.4.0

type OptionalBool struct {
	Value *bool
}

func NewOptionalBool added in v0.4.0

func NewOptionalBool(defaultValue *bool) OptionalBool

func (*OptionalBool) Set added in v0.4.0

func (f *OptionalBool) Set(val string) error

func (*OptionalBool) String added in v0.4.0

func (f *OptionalBool) String() string

String returns a string representation of the enum flag.

func (*OptionalBool) Type added in v0.4.0

func (f *OptionalBool) Type() string

type StringArray

type StringArray []string

StringArray is a Cobra-compatible named type for defining a string slice flag.

func NewStringArray

func NewStringArray(initial ...string) StringArray

NewStringArray returns a StringArray for a provided slice of values.

func (*StringArray) Set

func (sa *StringArray) Set(s string) error

Set comma-splits the provided string and assigns the results to the receiver. It returns an error if the string is not parseable.

func (*StringArray) String

func (sa *StringArray) String() string

String returns a comma-separated list of the items in the string array.

func (*StringArray) Type

func (sa *StringArray) Type() string

Type returns a string representation of the StringArray type.

Jump to

Keyboard shortcuts

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