util

package
v0.0.0-...-b8150c1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// TagDefault is the tag name for a default value of a field as recognized
	// by RegisterFlags.
	TagDefault = "def"
	// TagHelp is the tag name for a help message of a field as recognized
	// by RegisterFlags.
	TagHelp = "help"
	// TagOpt is the tag name for a one character option of a field as recognized
	// by RegisterFlags.  For example, a value of "d" reserves "-d" for the
	// command line argument.
	TagOpt = "opt"
	// TagSkip is the tag name which causes the field to be skipped by
	// RegisterFlags.
	TagSkip = "skip"
	// TagHide is the tag name which causes the field to be hidden
	TagHide = "hide"
)

Variables

This section is empty.

Functions

func CmdRunBegin

func CmdRunBegin(v *viper.Viper)

CmdRunBegin is called at the beginning of each cobra run function

func CopyMissingValues

func CopyMissingValues(src, dst interface{})

CopyMissingValues checks the dst interface for missing values and replaces them with value from src config struct. This does a deep copy of pointers.

func FileExists

func FileExists(name string) bool

func FlagString

func FlagString(v *viper.Viper, flags *pflag.FlagSet, name, short string, def string, desc string)

FlagString sets up a flag for a string, binding it to its name

func GetDefaultConfigFile

func GetDefaultConfigFile(cmdName string) string

func Marshal

func Marshal(from interface{}, what string) ([]byte, error)

func ParseObj

func ParseObj(obj interface{}, cb func(*Field) error, tags map[string]string) error

ParseObj parses an object structure, calling back with field info for each field

func RegisterFlags

func RegisterFlags(v *viper.Viper, flags *pflag.FlagSet, config interface{},
	tags map[string]string) error

RegisterFlags registers flags for all fields in an arbitrary 'config' object. This method recognizes the following field tags: "def" - the default value of the field; "opt" - the optional one character short name to use on the command line; "help" - the help message to display on the command line; "skip" - to skip the field.

func Unmarshal

func Unmarshal(from []byte, to interface{}, what string) error

func ValidateAndReturnAbsConf

func ValidateAndReturnAbsConf(configFilePath, homeDir, cmdName string) (string, string, error)

func ViperUnmarshal

func ViperUnmarshal(cfg interface{}, stringSliceFields []string, vp *viper.Viper) error

ViperUnmarshal is a work around for a bug in viper.Unmarshal This can be removed once https://github.com/spf13/viper/issues/327 is fixed and vendored.

Types

type Field

type Field struct {
	Name  string
	Path  string
	Type  reflect.Type
	Kind  reflect.Kind
	Leaf  bool
	Depth int
	Tag   reflect.StructTag
	Value interface{}
	Addr  interface{}
	Hide  string
}

Field is a field of an arbitrary struct

Jump to

Keyboard shortcuts

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