flag

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SerializePairs

func SerializePairs(pairs map[string]string) string

Serialize takes a map and generates a string that can be parsed by Set

Types

type BitFlags

type BitFlags struct {
	*OptionList
	Flags   int
	FlagMap map[string]int
}

BitFlags is a flag value type supporting a csv list of options stored as bits

func NewBitFlags

func NewBitFlags(permissibleOptions []string, defaultOptions string, flagMap map[string]int) (*BitFlags, error)

NewBitFlags initializes a simple bitflag version of the OptionList Type. flagMap is the mapping from option names to the integer value

func (*BitFlags) HasFlag

func (bf *BitFlags) HasFlag(f int) bool

func (*BitFlags) Set

func (bf *BitFlags) Set(s string) error

type DiscardFlag

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

DiscardFlag is a flag type that discards all options with a warning

func NewDiscardFlag

func NewDiscardFlag(name string) *DiscardFlag

func (*DiscardFlag) Set

func (df *DiscardFlag) Set(_ string) error

func (*DiscardFlag) String

func (df *DiscardFlag) String() string

func (*DiscardFlag) Type

func (df *DiscardFlag) Type() string

type OptionList

type OptionList struct {
	// Options field holds all specified and valid options. Should
	// not be modified.
	Options []string
	// contains filtered or unexported fields
}

OptionList is a flag value type supporting a csv list of options

func NewOptionList

func NewOptionList(permissibleOptions []string, defaultOptions string) (*OptionList, error)

NewOptionList initializes an OptionList. PermissibleOptions is the complete set of allowable options. It will set all options specified in defaultOptions as provided; they will all be cleared if this flag is passed in the CLI

func (*OptionList) PermissibleString

func (ol *OptionList) PermissibleString() string

func (*OptionList) Set

func (ol *OptionList) Set(s string) error

func (*OptionList) String

func (ol *OptionList) String() string

func (*OptionList) Type

func (ol *OptionList) Type() string

type PairList

type PairList struct {
	Pairs map[string]string
	// contains filtered or unexported fields
}

PairList is a flag value supporting a list of key=value pairs It will optionally validate the supplied keys and / or values It would parse something like "--arg foo=bar --arg baz=bar"

func MustNewPairList

func MustNewPairList(permissiblePairs map[string][]string, defaults map[string]string) *PairList

MustNewPairList is the same as NewPairList, but panics instead of returning error So check that your defaults are correct :-)

func NewPairList

func NewPairList(permissiblePairs map[string][]string, defaults map[string]string) (*PairList, error)

NewPairList initializes a new pair list If permissiblePairs is not empty, then it will validate keys and values. For every key in permissiblePairs, if the value is an empty list, then any value is allowed. If there is a list, then only those values are allowed for that. for example, { "a": {"1", "two", "cheese"}, "b" : {}} would accept a=1 and any b, but no other keys defaults is a list of default parameters

func (*PairList) Keys

func (pl *PairList) Keys() []string

Keys returns a sorted list of all present keys

func (*PairList) PermissibleString

func (pl *PairList) PermissibleString() string

PermissibleString generates a posix-cli-doc style string. For example, a=[b|c|d] w=[x|y|z] l=*

func (*PairList) Set

func (pl *PairList) Set(s string) error

Set parses a "k=v[,kk=vv...]" string

func (*PairList) SetOne

func (pl *PairList) SetOne(key, val string) error

SetOne validates and sets an individual key-value pair It will overwrite an existing value

func (*PairList) String

func (pl *PairList) String() string

String presents a k=v list in key=sorted order

func (*PairList) Type

func (pl *PairList) Type() string

Jump to

Keyboard shortcuts

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