cfgstruct

package
v0.0.0-...-eb3fb91 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 12 Imported by: 21

Documentation

Index

Constants

View Source
const (
	// AnySource is a source annotation for config values that can come from
	// a flag or file.
	AnySource = "any"

	// FlagSource is a source annotation for config values that just come from
	// flags (i.e. are never persisted to file).
	FlagSource = "flag"

	// BasicHelpAnnotationName is the name of the annotation used to indicate
	// a flag should be included in basic usage/help.
	BasicHelpAnnotationName = "basic-help"
)

Variables

This section is empty.

Functions

func Bind

func Bind(flags FlagSet, config interface{}, opts ...BindOpt)

Bind sets flags on a FlagSet that match the configuration struct 'config'. This works by traversing the config struct using the 'reflect' package.

func DefaultsType

func DefaultsType() string

DefaultsType returns the type of defaults (release/dev) this binary should use.

func FindConfigDirParam

func FindConfigDirParam() string

FindConfigDirParam returns '--config-dir' param from os.Args (if exists).

func FindDefaultsParam

func FindDefaultsParam() string

FindDefaultsParam returns '--defaults' param from os.Args (if it exists).

func FindFlagEarly

func FindFlagEarly(flagName string) string

FindFlagEarly retrieves the value of a flag before `flag.Parse` has been called.

func FindIdentityDirParam

func FindIdentityDirParam() string

FindIdentityDirParam returns '--identity-dir' param from os.Args (if exists).

func SetBoolAnnotation

func SetBoolAnnotation(flagset interface{}, name, key string, value bool)

SetBoolAnnotation sets an annotation (if it can) on flagset with a value of []string{"true|false"}.

func SetupFlag

func SetupFlag(log *zap.Logger, cmd *cobra.Command, dest *string, name, value, usage string)

SetupFlag sets up flags that are needed before `flag.Parse` has been called.

Types

type BindOpt

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

BindOpt is an option for the Bind method.

func ConfDir

func ConfDir(path string) BindOpt

ConfDir sets variables for default options called $CONFDIR.

func ConfigVar

func ConfigVar(name, val string) BindOpt

ConfigVar sets a variable for the default option called name.

func DefaultsFlag

func DefaultsFlag(cmd *cobra.Command) BindOpt

DefaultsFlag sets up the defaults=dev/release flag options, which is needed before `flag.Parse` has been called.

func IdentityDir

func IdentityDir(path string) BindOpt

IdentityDir sets a variable for the default option called $IDENTITYDIR.

func Prefix

func Prefix(prefix string) BindOpt

Prefix defines the used prefix, where configs are bound to.

func SetupMode

func SetupMode() BindOpt

SetupMode issues the bind in a mode where it does not ignore fields with the `setup:"true"` tag.

func UseDevDefaults

func UseDevDefaults() BindOpt

UseDevDefaults forces the bind call to use development defaults unless something else is provided as a subsequent option. Without a specific defaults setting, Bind will default to determining which defaults to use based on version.Build.Release.

func UseReleaseDefaults

func UseReleaseDefaults() BindOpt

UseReleaseDefaults forces the bind call to use release defaults unless something else is provided as a subsequent option. Without a specific defaults setting, Bind will default to determining which defaults to use based on version.Build.Release.

func UseTestDefaults

func UseTestDefaults() BindOpt

UseTestDefaults forces the bind call to use test defaults unless something else is provided as a subsequent option. Without a specific defaults setting, Bind will default to determining which defaults to use based on version.Build.Release.

type FlagSet

type FlagSet interface {
	BoolVar(p *bool, name string, value bool, usage string)
	IntVar(p *int, name string, value int, usage string)
	Int64Var(p *int64, name string, value int64, usage string)
	UintVar(p *uint, name string, value uint, usage string)
	Uint64Var(p *uint64, name string, value uint64, usage string)
	DurationVar(p *time.Duration, name string, value time.Duration, usage string)
	Float64Var(p *float64, name string, value float64, usage string)
	StringVar(p *string, name string, value string, usage string)
	StringArrayVar(p *[]string, name string, value []string, usage string)
	StringSliceVar(p *[]string, name string, value []string, usage string)
	Var(val pflag.Value, name string, usage string)
	MarkHidden(name string) error
}

FlagSet is an interface that matches *pflag.FlagSet.

Jump to

Keyboard shortcuts

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