Documentation ¶
Index ¶
- Constants
- Variables
- func Bind(cmd *cobra.Command, config interface{}, opts ...cfgstruct.BindOpt)
- func Ctx(cmd *cobra.Command) (context.Context, context.CancelFunc)
- func Exec(cmd *cobra.Command)
- func ExecCustomDebug(cmd *cobra.Command)
- func ExecWithCustomConfig(cmd *cobra.Command, debugEnabled bool, ...)
- func InitMetrics(ctx context.Context, log *zap.Logger, r *monkit.Registry, instanceID string) (err error)
- func InitMetricsWithCertPath(ctx context.Context, log *zap.Logger, r *monkit.Registry, certPath string) error
- func InitMetricsWithHostname(ctx context.Context, log *zap.Logger, r *monkit.Registry) error
- func LoadConfig(cmd *cobra.Command, vip *viper.Viper) error
- func NewLogger() (*zap.Logger, error)
- func NewLoggerWithOutputPaths(outputPaths ...string) (*zap.Logger, error)
- func SaveConfig(cmd *cobra.Command, outfile string, opts ...SaveConfigOption) error
- func Viper(cmd *cobra.Command) (*viper.Viper, error)
- func ViperWithCustomConfig(cmd *cobra.Command, ...) (*viper.Viper, error)
- type SaveConfigOption
- type SaveConfigOptions
Constants ¶
const DefaultCfgFilename = "config.yaml"
DefaultCfgFilename is the default filename used for storing a configuration.
Variables ¶
var ( // DebugAddrFlag for --debug.addr DebugAddrFlag = flag.String("debug.addr", "127.0.0.1:0", "address to listen on for debug endpoints") )
var ( // Error is a process error class Error = errs.Class("process error") )
Functions ¶
func Bind ¶ added in v0.13.0
Bind sets flags on a command that match the configuration struct 'config'. It ensures that the config has all of the values loaded into it when the command runs.
func Exec ¶
Exec runs a Cobra command. If a "config-dir" flag is defined it will be parsed and loaded using viper.
func ExecCustomDebug ¶ added in v0.33.2
ExecCustomDebug runs default configuration except the default debug is disabled.
func ExecWithCustomConfig ¶ added in v0.30.0
func ExecWithCustomConfig(cmd *cobra.Command, debugEnabled bool, loadConfig func(cmd *cobra.Command, vip *viper.Viper) error)
ExecWithCustomConfig runs a Cobra command. Custom configuration can be loaded.
func InitMetrics ¶
func InitMetrics(ctx context.Context, log *zap.Logger, r *monkit.Registry, instanceID string) (err error)
InitMetrics initializes telemetry reporting. Makes a telemetry.Client and calls its Run() method in a goroutine.
func InitMetricsWithCertPath ¶
func InitMetricsWithCertPath(ctx context.Context, log *zap.Logger, r *monkit.Registry, certPath string) error
InitMetricsWithCertPath initializes telemetry reporting, using the node ID corresponding to the given certificate as the telemetry instance ID.
func InitMetricsWithHostname ¶ added in v0.34.1
InitMetricsWithHostname initializes telemetry reporting, using the hostname as the telemetry instance ID.
func LoadConfig ¶ added in v0.30.0
LoadConfig loads configuration into *viper.Viper from file specified with "config-dir" flag.
func NewLoggerWithOutputPaths ¶ added in v0.28.0
NewLoggerWithOutputPaths is the same as NewLogger, but overrides the log output paths.
func SaveConfig ¶
func SaveConfig(cmd *cobra.Command, outfile string, opts ...SaveConfigOption) error
SaveConfig will save only the user-specific flags with default values to outfile with specific values specified in 'overrides' overridden.
func Viper ¶ added in v0.17.0
Viper returns the appropriate *viper.Viper for the command, creating if necessary.
func ViperWithCustomConfig ¶ added in v0.30.0
func ViperWithCustomConfig(cmd *cobra.Command, loadConfig func(cmd *cobra.Command, vip *viper.Viper) error) (*viper.Viper, error)
ViperWithCustomConfig returns the appropriate *viper.Viper for the command, creating if necessary. Custom config load logic can be defined with "loadConfig" parameter.
Types ¶
type SaveConfigOption ¶ added in v0.17.0
type SaveConfigOption func(*SaveConfigOptions)
SaveConfigOption is a function that updates the options for SaveConfig.
func SaveConfigRemovingDeprecated ¶ added in v0.17.0
func SaveConfigRemovingDeprecated() SaveConfigOption
SaveConfigRemovingDeprecated tells SaveConfig to not store deprecated flags.
func SaveConfigWithOverride ¶ added in v0.17.0
func SaveConfigWithOverride(name string, value interface{}) SaveConfigOption
SaveConfigWithOverride adds a single override to SaveConfig.
func SaveConfigWithOverrides ¶ added in v0.17.0
func SaveConfigWithOverrides(overrides map[string]interface{}) SaveConfigOption
SaveConfigWithOverrides sets the overrides to the provided map.
type SaveConfigOptions ¶ added in v0.17.0
SaveConfigOptions controls the behavior of SaveConfig.