flagutil

package
v1.101.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSecretFlag added in v1.41.1

func IsSecretFlag(s string) bool

IsSecretFlag returns true of s contains flag name with secret value, which shouldn't be exposed.

func ParseJSONMap added in v1.97.0

func ParseJSONMap(s string) (map[string]string, error)

ParseJSONMap parses s, which must contain JSON map of {"k1":"v1",...,"kN":"vN"}

func RegisterSecretFlag added in v1.41.1

func RegisterSecretFlag(flagName string)

RegisterSecretFlag registers flagName as secret.

This function must be called before starting logging. It cannot be called from concurrent goroutines.

Secret flags aren't exported at `/metrics` page.

func Usage added in v1.49.0

func Usage(s string)

Usage prints s and optional description for all the flags if -h or -help flag is passed to the app.

func WriteFlags added in v1.68.0

func WriteFlags(w io.Writer)

WriteFlags writes all the explicitly set flags to w.

Types

type ArrayBool added in v1.50.0

type ArrayBool []bool

ArrayBool is a flag that holds an array of booleans values.

Has the same api as ArrayString.

func NewArrayBool added in v1.50.0

func NewArrayBool(name, description string) *ArrayBool

NewArrayBool returns new ArrayBool with the given name and description.

func (*ArrayBool) GetOptionalArg added in v1.50.0

func (a *ArrayBool) GetOptionalArg(argIdx int) bool

GetOptionalArg returns optional arg under the given argIdx.

func (*ArrayBool) IsBoolFlag added in v1.50.0

func (a *ArrayBool) IsBoolFlag() bool

IsBoolFlag implements flag.IsBoolFlag interface

func (*ArrayBool) Set added in v1.50.0

func (a *ArrayBool) Set(value string) error

Set implements flag.Value interface

func (*ArrayBool) String added in v1.50.0

func (a *ArrayBool) String() string

String implements flag.Value interface

type ArrayBytes added in v1.82.0

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

ArrayBytes is flag that holds an array of Bytes.

Has the same api as ArrayString.

func NewArrayBytes added in v1.82.0

func NewArrayBytes(name string, defaultValue int64, description string) *ArrayBytes

NewArrayBytes returns new ArrayBytes with the given name, defaultValue and description.

func (*ArrayBytes) GetOptionalArg added in v1.93.0

func (a *ArrayBytes) GetOptionalArg(argIdx int) int64

GetOptionalArg returns optional arg under the given argIdx, or default value

func (*ArrayBytes) Set added in v1.82.0

func (a *ArrayBytes) Set(value string) error

Set implemented flag.Value interface

func (*ArrayBytes) String added in v1.82.0

func (a *ArrayBytes) String() string

String implements flag.Value interface

type ArrayDuration added in v1.50.0

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

ArrayDuration is a flag that holds an array of time.Duration values.

Has the same api as ArrayString.

func NewArrayDuration added in v1.50.0

func NewArrayDuration(name string, defaultValue time.Duration, description string) *ArrayDuration

NewArrayDuration returns new ArrayDuration with the given name, defaultValue and description.

func (*ArrayDuration) GetOptionalArg added in v1.93.0

func (a *ArrayDuration) GetOptionalArg(argIdx int) time.Duration

GetOptionalArg returns optional arg under the given argIdx, or default value, if argIdx not found.

func (*ArrayDuration) Set added in v1.50.0

func (a *ArrayDuration) Set(value string) error

Set implements flag.Value interface

func (*ArrayDuration) String added in v1.50.0

func (a *ArrayDuration) String() string

String implements flag.Value interface

type ArrayInt added in v1.53.0

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

ArrayInt is flag that holds an array of ints.

Has the same api as ArrayString.

func NewArrayInt added in v1.53.0

func NewArrayInt(name string, defaultValue int, description string) *ArrayInt

NewArrayInt returns new ArrayInt with the given name, defaultValue and description.

func (*ArrayInt) GetOptionalArg added in v1.93.0

func (a *ArrayInt) GetOptionalArg(argIdx int) int

GetOptionalArg returns optional arg under the given argIdx or default value.

func (*ArrayInt) Set added in v1.53.0

func (a *ArrayInt) Set(value string) error

Set implements flag.Value interface

func (*ArrayInt) String added in v1.53.0

func (a *ArrayInt) String() string

String implements flag.Value interface

func (*ArrayInt) Values added in v1.96.0

func (a *ArrayInt) Values() []int

Values returns all the values for a.

type ArrayString added in v1.82.0

type ArrayString []string

ArrayString is a flag that holds an array of strings.

It may be set either by specifying multiple flags with the given name passed to NewArray or by joining flag values by comma.

The following example sets equivalent flag array with two items (value1, value2):

-foo=value1 -foo=value2
-foo=value1,value2

Each flag value may contain commas inside single quotes, double quotes, [], () or {} braces. For example, -foo=[a,b,c] defines a single command-line flag with `[a,b,c]` value.

Flag values may be quoted. For instance, the following arg creates an array of ("a", "b,c") items:

-foo='a,"b,c"'

func NewArrayString added in v1.82.0

func NewArrayString(name, description string) *ArrayString

NewArrayString returns new ArrayString with the given name and description.

func (*ArrayString) GetOptionalArg added in v1.82.0

func (a *ArrayString) GetOptionalArg(argIdx int) string

GetOptionalArg returns optional arg under the given argIdx.

func (*ArrayString) Set added in v1.82.0

func (a *ArrayString) Set(value string) error

Set implements flag.Value interface

func (*ArrayString) String added in v1.82.0

func (a *ArrayString) String() string

String implements flag.Value interface

type Bytes added in v1.40.1

type Bytes struct {
	// N contains parsed value for the given flag.
	N int64
	// contains filtered or unexported fields
}

Bytes is a flag for holding size in bytes.

It supports the following optional suffixes for values: KB, MB, GB, TB, KiB, MiB, GiB, TiB.

func NewBytes added in v1.40.1

func NewBytes(name string, defaultValue int64, description string) *Bytes

NewBytes returns new `bytes` flag with the given name, defaultValue and description.

func (*Bytes) IntN added in v1.79.7

func (b *Bytes) IntN() int

IntN returns the stored value capped by int type.

func (*Bytes) Set added in v1.40.1

func (b *Bytes) Set(value string) error

Set implements flag.Value interface

func (*Bytes) String added in v1.40.1

func (b *Bytes) String() string

String implements flag.Value interface

type DictInt added in v1.96.0

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

DictInt allows specifying a dictionary of named ints in the form `name1:value1,...,nameN:valueN`.

func NewDictInt added in v1.96.0

func NewDictInt(name string, defaultValue int, description string) *DictInt

NewDictInt creates DictInt with the given name, defaultValue and description.

func (*DictInt) Get added in v1.96.0

func (di *DictInt) Get(key string) int

Get returns value for the given key.

Default value is returned if key isn't found in di.

func (*DictInt) Set added in v1.96.0

func (di *DictInt) Set(value string) error

Set implements flag.Value interface

func (*DictInt) String added in v1.96.0

func (di *DictInt) String() string

String implements flag.Value interface

type Duration added in v1.45.0

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

Duration is a flag for holding duration.

func NewDuration added in v1.45.0

func NewDuration(name string, defaultValue string, description string) *Duration

NewDuration returns new `duration` flag with the given name, defaultValue and description.

DefaultValue is in months.

func (*Duration) Duration added in v1.94.0

func (d *Duration) Duration() time.Duration

Duration returns d as time.Duration

func (*Duration) Milliseconds added in v1.94.0

func (d *Duration) Milliseconds() int64

Milliseconds returns d in milliseconds

func (*Duration) Set added in v1.45.0

func (d *Duration) Set(value string) error

Set implements flag.Value interface

func (*Duration) String added in v1.45.0

func (d *Duration) String() string

String implements flag.Value interface

type Password added in v1.97.0

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

Password is a flag holding a password.

If the flag value is file:///path/to/file or http://host/path , then its contents is automatically re-read from the given file or url

func NewPassword added in v1.97.0

func NewPassword(name, description string) *Password

NewPassword returns new `password` flag with the given name and description.

The password value is hidden when calling Password.String() for security reasons, since the returned value can be put in logs. Call Password.Get() for obtaining the real password value.

func (*Password) Get added in v1.97.0

func (p *Password) Get() string

Get returns the current p value.

It re-reads p value from the file:///path/to/file or http://host/path if they were passed to Password.Set.

func (*Password) Set added in v1.97.0

func (p *Password) Set(value string) error

Set implements flag.Value interface.

func (*Password) String added in v1.97.0

func (p *Password) 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