scan

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDescTag     = "desc"
	DefaultFlagTag     = "flag"
	DefaultEnvTag      = "env"
	DefaultFlagDivider = "-"
	DefaultEnvDivider  = "_"
	DefaultFlatten     = true
)

Variables

View Source
var ErrNotPointerToStruct = errors.New("object must be a pointer to struct or interface")

ErrNotPointerToStruct indicates that a provided data container is not a pointer to a struct. Only pointers to structs are valid data containers for options.

View Source
var ErrScan = errors.New("scan error")

ErrScan indicates an error in scanning struct fields.

Functions

func Type

func Type(data interface{}, handler Handler) error

Type actually scans the type, recursively if needed.

Types

type FlagFunc

type FlagFunc func(flag string, tag tag.MultiTag, val reflect.Value) error

FlagFunc is a generic function that can be applied to each value that will end up being a flags *Flag, so that users can perform more arbitrary operations on each, such as checking for completer implementations, bind to viper configurations, etc.

type Handler

type Handler func(reflect.Value, *reflect.StructField) (bool, error)

Handler is a generic handler used for scanning both commands and group structs alike.

type OptFunc

type OptFunc func(opt *Opts)

OptFunc sets values in opts structure.

func CopyOpts

func CopyOpts(val Opts) OptFunc

type Opts

type Opts struct {
	DescTag     string
	FlagTag     string
	Prefix      string
	EnvPrefix   string
	FlagDivider string
	EnvDivider  string
	Flatten     bool
	ParseAll    bool
	Validator   ValidateFunc
	FlagFunc    FlagFunc
}

func DefOpts

func DefOpts() Opts

func (Opts) Apply

func (o Opts) Apply(optFuncs ...OptFunc) Opts

type ValidateFunc

type ValidateFunc func(val string, field reflect.StructField, cfg interface{}) error

ValidateFunc describes a validation func, that takes string val for flag from command line, field that's associated with this flag in structure cfg. Also works for positional arguments. Should return error if validation fails.

Jump to

Keyboard shortcuts

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