Documentation ¶
Index ¶
- func AppendStringArgs(cmd *cobra.Command, args []string, key string) []string
- func AppendStringArgsf(format string, cmd *cobra.Command, args []string, key string) []string
- func AppendStringSplitArgs(cmd *cobra.Command, args []string, key string, splitPattern string) []string
- func BuildEnvKey(cmd *cobra.Command, envPrefix string, keyName string) string
- func CheckRequiredFlags(cmd *cobra.Command, requiredFlags []string) error
- func PrefixKey(cmd *cobra.Command, keyName string) string
- func ViperBindPFlag(cmd *cobra.Command, name string)
- func ViperBindPFlagSet(cmd *cobra.Command, flags *pflag.FlagSet)
- func ViperBindPersistentPFlag(cmd *cobra.Command, name string)
- func ViperGetBool(cmd *cobra.Command, key string) bool
- func ViperGetDuration(cmd *cobra.Command, key string) time.Duration
- func ViperGetFloat64(cmd *cobra.Command, key string) float64
- func ViperGetInt(cmd *cobra.Command, key string) int
- func ViperGetSizeInBytes(cmd *cobra.Command, key string) uint
- func ViperGetString(cmd *cobra.Command, key string) string
- func ViperGetStringMap(cmd *cobra.Command, key string) map[string]interface{}
- func ViperGetStringMapString(cmd *cobra.Command, key string) map[string]string
- func ViperGetStringMapStringSlice(cmd *cobra.Command, key string) map[string][]string
- func ViperGetStringSlice(cmd *cobra.Command, key string) []string
- func ViperGetTime(cmd *cobra.Command, key string) time.Time
- func ViperIsSet(cmd *cobra.Command, key string) bool
- func ViperSet(cmd *cobra.Command, key, value string)
- type Option
- func WithConfigName(configName string) Option
- func WithConfigType(configType string) Option
- func WithEnvPrefix(envPrefix string) Option
- func WithFlags(flags *pflag.FlagSet) Option
- func WithLogFormatKey(logFormatKey string) Option
- func WithLogLevelKey(logLevelKey string) Option
- func WithUserConfigPaths(userConfigPaths []string) Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendStringArgs ¶
AppendStringArgs appends viper value to existing args slice
func AppendStringArgsf ¶
AppendStringArgsf appends viper value to existing args slice with optional formatted output with key and value
func AppendStringSplitArgs ¶
func AppendStringSplitArgs(cmd *cobra.Command, args []string, key string, splitPattern string) []string
AppendSplitArgs appends viper value to existing args slice after splitting them by splitPattern (default regex whitespace)
func BuildEnvKey ¶ added in v1.5.0
BuildEnvKey returns a fully constructed environment variable name
func CheckRequiredFlags ¶
CheckRequiredFlags exits with error when one ore more required flags are not set
func ViperBindPFlag ¶
ViperBindPFlag is a convenience wrapper over viper.BindPFlag for local flags
func ViperBindPFlagSet ¶
ViperBindPFlagSet is a convenience wrapper over viper.BindPFlag for local FlagSet
if flags is nil, the cmd.Flags() will be used
func ViperBindPersistentPFlag ¶
ViperBindPersistentPFlag is a convenience wrapper over viper.BindPFlag for persistent flags
func ViperGetBool ¶
ViperGetBool is a convenience wrapper that returns the value associated with the key as a boolean.
func ViperGetDuration ¶
ViperGetDuration is a convenience wrapper that returns the value associated with the key as a duration.
func ViperGetFloat64 ¶ added in v1.4.3
ViperGetFloat64 is a convenience wrapper that returns the value associated with the key as a float64.
func ViperGetInt ¶
ViperGetInt is a convenience wrapper that returns the value associated with the key as an integer.
func ViperGetSizeInBytes ¶ added in v1.4.3
ViperGetSizeInBytes is a convenience wrapper that returns the size of the value associated with the given key
func ViperGetString ¶
ViperGetString is a convenience wrapper that returns the value associated with the key as a string.
func ViperGetStringMap ¶ added in v1.4.3
ViperGetStringMap is a convenience wrapper that returns the value associated with the key as a map of interfaces.
func ViperGetStringMapString ¶ added in v1.4.3
ViperGetStringMapString is a convenience wrapper that returns the value associated with the key as a map of strings.
func ViperGetStringMapStringSlice ¶ added in v1.4.3
ViperGetStringMapStringSlice is a convenience wrapper that returns the value associated with the key as a map to a slice of strings.
func ViperGetStringSlice ¶ added in v1.4.3
ViperGetStringSlice is a convenience wrapper that returns the value associated with the key as a slice of strings.
func ViperGetTime ¶ added in v1.4.3
ViperGetTime is a convenience wrapper that returns the value associated with the key as time.
func ViperIsSet ¶
ViperIsSet is a convenience wrapper returning true if a key is set. Case insensitive for keys.
Types ¶
type Option ¶ added in v1.5.0
type Option func(*Options)
func WithConfigName ¶ added in v1.5.0
func WithConfigType ¶ added in v1.5.0
func WithEnvPrefix ¶ added in v1.5.0
func WithLogFormatKey ¶ added in v1.5.0
func WithLogLevelKey ¶ added in v1.5.0
func WithUserConfigPaths ¶ added in v1.5.0
type Options ¶ added in v1.5.0
type Options struct { EnvPrefix string ConfigType string ConfigName string UserConfigPaths []string LogLevel string LogLevelKey string LogFormat string LogFormatKey string Flags *pflag.FlagSet }
func NewOptions ¶ added in v1.5.0
NewOptions sets default Options overriding with options
func (*Options) InitConfig ¶ added in v1.5.0
InitConfig reads in config file and ENV variables if set.