cli

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 10 Imported by: 18

README

common

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckErr

func CheckErr(err error)

CheckErr ends in a fatal log if err is not nil.

func CheckErrf

func CheckErrf(format string, err error)

CheckErrf ends in a fatal log if err is not nil.

func ConfigureCLI

func ConfigureCLI(v *viper.Viper, envPrefix string, flags []Flag, flagSet *pflag.FlagSet)

ConfigureCLI configures a Viper environment with flags and envs.

func ConfigureLogging

func ConfigureLogging(v *viper.Viper, logLevels []string) error

ConfigureLogging configures the default logger with the right setup depending flag/envs. If logLevels is not nil, only logLevels values will be configured to Info/Debug depending on viper flags. if logLevels is nil, all sub-logs will be configured.

func ExpandEnvVars

func ExpandEnvVars(v *viper.Viper, settings map[string]interface{})

ExpandEnvVars expands env vars present in the config.

func HandleInterrupt

func HandleInterrupt(cleanup func())

HandleInterrupt attempts to cleanup while allowing the user to force stop the process.

func MarshalConfig

func MarshalConfig(v *viper.Viper, pretty bool, maskedFields ...string) ([]byte, error)

MarshalConfig marshals a *viper.Viper config to JSON. pretty controls if the result is indented or not. It replaces the masked fields with three asterisks, if they are present.

func ParseStringSlice

func ParseStringSlice(v *viper.Viper, key string) []string

ParseStringSlice returns a single slice of values that may have been set by either repeating a flag or using comma separation in a single flag. This is used to enable repeated flags as well as env vars that can't be repeated. In either case, Viper understands how to write the config entry as a list.

Types

type Flag

type Flag struct {
	Name        string
	DefValue    interface{}
	Description string
}

Flag describes a configuration flag.

Jump to

Keyboard shortcuts

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