Documentation
¶
Index ¶
- Constants
- func Register[T any](to ToStr, from FromStr)
- type FromStr
- type SConf
- func (cnf *SConf[X]) GetConf() *X
- func (cnf *SConf[X]) GetConfAny() any
- func (cnf *SConf[X]) MarshalYAML() ([]byte, error)
- func (cnf *SConf[X]) Read(args []string) (cmd *cobra.Command, ferr, aerr error)
- func (cnf *SConf[X]) ReadwithCMDLine() (cmd *cobra.Command, ferr, aerr error)
- func (cnf *SConf[X]) UnmarshalYAML(buf []byte) error
- type SConfInt
- type SconfOption
- type ToStr
Constants ¶
const (
DefCfgFileFlagName = "cfgfromfile"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SConf ¶
type SConf[X any] struct { Filler *myflags.Filler // contains filtered or unexported fields }
SConf represents a set of configurations as a struct
func NewSConf ¶
func NewSConf[X any](def *X, name, usage string, options ...SconfOption[X]) (*SConf[X], error)
NewSConf returns a new SConf instance, def is a pointer to configruation struct with default value, defpath is the default configuration file path, it could be overriden by using command line arg "-f", could be "" means no default path
func (*SConf[X]) GetConfAny ¶
func (*SConf[X]) MarshalYAML ¶
MarshalYAML marshal config value into YAML
func (*SConf[X]) Read ¶
Read read configuration first from file, then from commandline args, commandline args will be read regardless if file read succeds, cmd is the command get executed, ferr is error of file reading, aerr is error of commandline args reading. if there is ferr and/or aerr, it could be treated as non-fatal failure thanks to mix&match and priority support.
func (*SConf[X]) ReadwithCMDLine ¶
ReadCMDLine is same as Read, expcept the args is os.Args[1:]
func (*SConf[X]) UnmarshalYAML ¶
UnmarshalYAML unmrshal YAML encoded buf into config value
type SconfOption ¶
func WithConfigFileFlagName ¶
func WithConfigFileFlagName[X any](name string) SconfOption[X]
WithConfigFileFlagName sepcifies the flag name of loading config file, default is defined by const DefCfgFileFlagName
func WithDefaultConfigFilePath ¶
func WithDefaultConfigFilePath[X any](def string) SconfOption[X]
WithDefaultConfigFilePath specifies default config file path, if it is empty, then there is no reading from config file
func WithFillFlags ¶
func WithFillFlags[X any](fill bool) SconfOption[X]
WithFillFlags specifies whether to fill flags
func WithFillOptions ¶
func WithFillOptions[X any](optlist []myflags.FillerOption) SconfOption[X]
WithFillOptions specifies options used to create myflags.Filler