flags

package
v0.0.0-...-b1e9806 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TagName defines the name of struct tag to look for
	TagName = "flag"
)

Variables

View Source
var (
	ErrMustBePtr           = errors.New("must marshall into a pointer")
	ErrNilStruct           = errors.New("cannot unmarshall flags into nil structure")
	ErrRequireStruct       = errors.New(("must unmarshall into struct"))
	ErrFieldNotAddressable = errors.New("field cannot be set as its not addressable")
	ErrFlagNotFound        = errors.New("flag not found in flagset")
	ErrUnsupportedType     = errors.New("type not supported for unmarshalling")
)
View Source
var (
	// ErrFlagMissing is an error when there is no flag with a given name
	ErrFlagMissing = errors.New("flag missing")
)

Functions

func BindFlags

func BindFlags(cmd *cobra.Command)

func ConvertToMap

func ConvertToMap(fs *pflag.FlagSet) map[string]string

ConvertToMap will convert a flagset to a map

func CopyFlagValue

func CopyFlagValue(sourceFlagName, destinationFlagName string, fs *pflag.FlagSet, ignoreNotFound bool) error

func CreateCommandFlags

func CreateCommandFlags(cmd *cobra.Command, cs config.ConfigurationSet) error

func CreateFlagsFromConfig

func CreateFlagsFromConfig(cs config.ConfigurationSet) (*pflag.FlagSet, error)

CreateFlagsFromConfig will create a FlagSet from a configuration set

func ExistsWithValue

func ExistsWithValue(name string, flags *pflag.FlagSet) bool

ExistsWithValue returns true if a flag exists in a flagset and has a value and that value is non-empty

func GetFlagValueDirect

func GetFlagValueDirect(args []string, longName, shortName string) (string, error)

GetFlagValueDirect will get a flag value directly from args or config. Note: this should only be used in exceptional circumstances

func ParseFlagMultiValueToMap

func ParseFlagMultiValueToMap(flag string) map[string]string

func PopulateConfigFromCommand

func PopulateConfigFromCommand(cmd *cobra.Command, cs config.ConfigurationSet)

func PopulateConfigFromFlags

func PopulateConfigFromFlags(flags *pflag.FlagSet, cs config.ConfigurationSet)

func Unmarshal

func Unmarshal(flagset *pflag.FlagSet, out interface{}, opts ...BinderOption) error

Unmarshal will decode the flagset into the out interface

Types

type BinderOption

type BinderOption func(*flagBinder)

BinderOption defines a functional option for creations of the flags binder

func IgnoreFlagNotFound

func IgnoreFlagNotFound() BinderOption

IgnoreFlagNotFound is an option that specifies that if a flag doesn't exist then no error should be returned

Jump to

Keyboard shortcuts

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