flagutil

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: Apache-2.0 Imports: 8 Imported by: 8

Documentation

Overview

Package flagutil contains flags that parse string lists and string maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DualFormatBoolVar added in v0.10.0

func DualFormatBoolVar(p *bool, name string, value bool, usage string)

DualFormatBoolVar creates a flag which supports both dashes and underscores

func DualFormatInt64Var added in v0.10.0

func DualFormatInt64Var(p *int64, name string, value int64, usage string)

DualFormatInt64Var creates a flag which supports both dashes and underscores

func DualFormatIntVar added in v0.10.0

func DualFormatIntVar(p *int, name string, value int, usage string)

DualFormatIntVar creates a flag which supports both dashes and underscores

func DualFormatStringListVar added in v0.10.0

func DualFormatStringListVar(p *[]string, name string, value []string, usage string)

DualFormatStringListVar creates a flag which supports both dashes and underscores

func DualFormatStringVar added in v0.10.0

func DualFormatStringVar(p *string, name string, value string, usage string)

DualFormatStringVar creates a flag which supports both dashes and underscores

func StringListVar

func StringListVar(p *[]string, name string, defaultValue []string, usage string)

StringListVar defines a []string flag with the specified name, value and usage string. The argument 'p' points to a []string in which to store the value of the flag.

Types

type OptionalFlag added in v0.11.0

type OptionalFlag interface {
	flag.Value
	IsSet() bool
}

OptionalFlag augements the flag.Value interface with a method to determine if a flag was set explicitly on the comand-line.

Though not part of the interface, because the return type would be different for each implementation, by convention, each implementation should define a Get() method to access the underlying value.

type OptionalFloat64 added in v0.11.0

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

OptionalFloat64 implements OptionalFlag for float64 values.

func NewOptionalFloat64 added in v0.11.0

func NewOptionalFloat64(val float64) *OptionalFloat64

NewOptionalFloat64 returns an OptionalFloat64 with the specified value as its starting value.

func (*OptionalFloat64) Get added in v0.11.0

func (f *OptionalFloat64) Get() float64

Get returns the underlying float64 value of this flag. If the flag was not explicitly set, this will be the initial value passed to the constructor.

func (*OptionalFloat64) IsSet added in v0.11.0

func (f *OptionalFloat64) IsSet() bool

IsSet is part of the OptionalFlag interface.

func (*OptionalFloat64) Set added in v0.11.0

func (f *OptionalFloat64) Set(arg string) error

Set is part of the flag.Value interface.

func (*OptionalFloat64) String added in v0.11.0

func (f *OptionalFloat64) String() string

String is part of the flag.Value interface.

type OptionalString added in v0.11.0

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

OptionalString implements OptionalFlag for string values.

func NewOptionalString added in v0.11.0

func NewOptionalString(val string) *OptionalString

NewOptionalString returns an OptionalString with the specified value as its starting value.

func (*OptionalString) Get added in v0.11.0

func (f *OptionalString) Get() string

Get returns the underlying string value of this flag. If the flag was not explicitly set, this will be the initial value passed to the constructor.

func (*OptionalString) IsSet added in v0.11.0

func (f *OptionalString) IsSet() bool

IsSet is part of the OptionalFlag interface.

func (*OptionalString) Set added in v0.11.0

func (f *OptionalString) Set(arg string) error

Set is part of the flag.Value interface.

func (*OptionalString) String added in v0.11.0

func (f *OptionalString) String() string

String is part of the flag.Value interface.

type StringListValue

type StringListValue []string

StringListValue is a []string flag that accepts a comma separated list of elements. To include an element containing a comma, quote it with a backslash '\'.

func (StringListValue) Get

func (value StringListValue) Get() interface{}

Get returns the []string value of this flag.

func (*StringListValue) Set

func (value *StringListValue) Set(v string) error

Set sets the value of this flag from parsing the given string.

func (StringListValue) String

func (value StringListValue) String() string

String returns the string representation of this flag.

type StringMapValue

type StringMapValue map[string]string

StringMapValue is a map[string]string flag. It accepts a comma-separated list of key value pairs, of the form key:value. The keys cannot contain colons.

func (StringMapValue) Get

func (value StringMapValue) Get() interface{}

Get returns the map[string]string value of this flag.

func (*StringMapValue) Set

func (value *StringMapValue) Set(v string) error

Set sets the value of this flag from parsing the given string.

func (StringMapValue) String

func (value StringMapValue) String() string

String returns the string representation of this flag.

type StringSetFlag added in v0.11.0

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

StringSetFlag can be used to collect multiple instances of a flag into a set of values.

For example, defining the following:

var x flagutil.StringSetFlag
flag.Var(&x, "foo", "")

And then specifying "-foo x -foo y -foo x", will result in a set of {x, y}.

In addition to implemnting the standard flag.Value interface, it also provides an implementation of pflag.Value, so it is usable in libraries like cobra.

func (*StringSetFlag) Set added in v0.11.0

func (set *StringSetFlag) Set(s string) error

Set is part of the pflag.Value and flag.Value interfaces.

func (*StringSetFlag) String added in v0.11.0

func (set *StringSetFlag) String() string

String is part of the pflag.Value and flag.Value interfaces.

func (*StringSetFlag) ToSet added in v0.11.0

func (set *StringSetFlag) ToSet() sets.String

ToSet returns the underlying string set, or an empty set if the underlying set is nil.

func (*StringSetFlag) Type added in v0.11.0

func (set *StringSetFlag) Type() string

Type is part of the pflag.Value interface.

Jump to

Keyboard shortcuts

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