flags

package
v2.11.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ValidatedValue

type ValidatedValue[T any] struct {
	// contains filtered or unexported fields
}

ValidatedValue implements `pflag.Value` interface. It can be used for hooking up arbitrary validation logic to any type. It should be passed to `pflag.FlagSet.Var()`.

func NewValidatedValue

func NewValidatedValue[T any](variable *T, constructor func(flagValue string) (T, error), opts ...ValidatedValueOpt[T]) ValidatedValue[T]

NewValidatedValue creates a validated variable of type T. Constructor should validate the input and return an error in case of any failures. If validation passes, constructor should return a value that's to be set in the variable. The constructor accepts a flagValue that is raw input from user's command line (or an env variable that was bind to the flag, see: bindEnvVars). It accepts a variadic list of options that can be used e.g. to set the default value or override the type name.

func (ValidatedValue[T]) Set

func (v ValidatedValue[T]) Set(s string) error

func (ValidatedValue[T]) String

func (v ValidatedValue[T]) String() string

func (ValidatedValue[T]) Type

func (v ValidatedValue[T]) Type() string

type ValidatedValueOpt

type ValidatedValueOpt[T any] func(*ValidatedValue[T])

func WithDefault

func WithDefault[T any](defaultValue T) ValidatedValueOpt[T]

WithDefault sets the default value for the validated variable.

func WithTypeNameOverride

func WithTypeNameOverride[T any](typeName string) ValidatedValueOpt[T]

WithTypeNameOverride overrides the type name that's printed in the help message.

Jump to

Keyboard shortcuts

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