viperconfig

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package viperconfig is a fancy interface allowing you to bind viper commands in your individual packages without having to make some insane monolithic file Credit goes to the stacklok folks: https://github.com/stacklok/minder/blob/main/internal/util/configutils.go TO DO: convert allthethings over to using utils.BindConfigFlag()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindConfigFlag

func BindConfigFlag[V any](
	v *viper.Viper,
	flags *pflag.FlagSet,
	viperPath string,
	cmdLineArg string,
	defaultValue V,
	help string,
	binder FlagInst[V],
) error

BindConfigFlag is a helper function that binds a configuration value to a flag v: The viper.Viper object used to retrieve the configuration value flags: The pflag.FlagSet object used to retrieve the flag value viperPath: The path used to retrieve the configuration value from Viper cmdLineArg: The flag name used to check if the flag has been set and to retrieve its value help: The help text for the flag defaultValue: A default value used to determine the type of the flag (string, int, etc.) binder: A function that creates a flag and returns a pointer to the value

func BindConfigFlagWithShort

func BindConfigFlagWithShort[V any](
	v *viper.Viper,
	flags *pflag.FlagSet,
	viperPath string,
	cmdLineArg string,
	short string,
	defaultValue V,
	help string,
	binder FlagInstShort[V],
) error

BindConfigFlagWithShort is a helper function that binds a configuration value to a flag v: The viper.Viper object used to retrieve the configuration value flags: The pflag.FlagSet object used to retrieve the flag value viperPath: The path used to retrieve the configuration value from Viper cmdLineArg: The flag name used to check if the flag has been set and to retrieve its value short: The short name for the flag help: The help text for the flag defaultValue: A default value used to determine the type of the flag (string, int, etc.) binder: A function that creates a flag and returns a pointer to the value

Types

type FlagInst

type FlagInst[V any] func(name string, value V, usage string) *V

FlagInst is a function that creates a flag and returns a pointer

type FlagInstShort

type FlagInstShort[V any] func(name, shorthand string, value V, usage string) *V

FlagInstShort is a function that creates a flag and returns a pointer

Jump to

Keyboard shortcuts

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