Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionConf ¶
type ActionConf struct {
// contains filtered or unexported fields
}
ActionConf represents a command with multiple actions, e.g. an zip file utility might have full command line structure:
- examplezip show -zipf <zip_filename> -fname <filename_inside_zip> - examplezip zip -folder <foldername> -zipf <zip_filename> - examplezip extract -zipf <zip_filename> -output <output_path>
"show/zip/extract" in this example represents different action, and each action requires different set of configuration/parameters, ActionConf allows user to specify a map betweening an action(string) with *SConf[any]
func NewActionConfWithCMDLine ¶
func NewActionConfWithCMDLine(list map[string]ConfigWithDefCfgFilePath) (*ActionConf, error)
NewActionConfWithCMDLine creates ActionConf via list, key is the action, value is the a config struct implements ConfigWithDefCfgFilePath interface.
func (*ActionConf) GetLoadedAction ¶
func (acnf *ActionConf) GetLoadedAction() string
GetLoadedAction returns the loaded action, "" means not loaded
func (*ActionConf) GetLoadedConf ¶
func (acnf *ActionConf) GetLoadedConf() any
GetLoadedConf returns loaded SConf, nil means not loaded
func (*ActionConf) Read ¶
func (acnf *ActionConf) Read(args []string) (actionerr, ferr, aerr error)
Read loads configuration from args and/or config file args format is following: - if there is only one action: the same as SConf.Read - otherwise, args[0] is the action, action is case-sensistive
return following errors: - actionerr: error during parsing action, application should check & handle this error - ferr&aerr: same sa SConf
func (*ActionConf) ReadwithCMDLine ¶
func (acnf *ActionConf) ReadwithCMDLine() (actionerr, ferr, aerr error)
type ConfigWithDefCfgFilePath ¶
type ConfigWithDefCfgFilePath interface {
DefaultCfgFilePath() string //return "" to be ignored
}
type SConf ¶
type SConf[T any] struct { // contains filtered or unexported fields }
SConf represents a set of configurations as a struct
func NewSConf ¶
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 fset is the flagset to bind
func NewSConfCMDLine ¶
NewSConfCMDLine is same as NewSConf, just use flag.CommandLine as the flagset
func (*SConf[T]) GetConfAny ¶
func (*SConf[T]) MarshalYAML ¶
MarshalYAML marshal config value into YAML
func (*SConf[T]) Read ¶
Read read configuration first from file, then flagset from args, flagset will be read regardless if file read succeds, ferr is error of file reading, aerr is error of flagset 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[T]) ReadwithCMDLine ¶
ReadCMDLine is same as Read, expcept the args is os.Args[1:]
func (*SConf[T]) UnmarshalYAML ¶
UnmarshalYAML unmrshal YAML encoded buf into config value