Documentation ¶
Index ¶
- Variables
- func CommandArgs(allArgs map[string]reflect.Value)
- func Config(cfg any, defaultFile string) ([]string, error)
- func FieldArgNames(obj any, allArgs map[string]reflect.Value)
- func IncludeStack(cfg Includer) ([]string, error)
- func LogFileName(logName, netName, runName string) string
- func OpenFS(cfg any, fsys fs.FS, file string) error
- func OpenWithIncludes(cfg any, file string) error
- func ParseArg(s string, args []string, allArgs map[string]reflect.Value, errNotFound bool) (a []string, err error)
- func ParseArgs(cfg any, args []string, allArgs map[string]reflect.Value, errNotFound bool) ([]string, error)
- func Save(cfg any, file string) error
- func SetArgValue(name string, fval reflect.Value, value string) error
- func SetFromArgs(cfg any, args []string) (nonFlags []string, err error)
- func SetFromDefaults(cfg any) error
- func SetLogFile(logs *elog.Logs, configOn bool, mode etime.Modes, time etime.Times, ...)
- func Usage(cfg any) string
- type Includer
- type TestEnum
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultEncoding is the default encoding format for config files. // currently toml is the only supported format, but others could be added // if needed. DefaultEncoding = "toml" // IncludePaths is a list of file paths to try for finding config files // specified in Include field or via the command line --config --cfg or -c args. // Set this prior to calling Config -- default is current directory '.' and 'configs' IncludePaths = []string{".", "configs"} // NonFlagArgs are the command-line args that remain after all the flags have // been processed. This is set after the call to Config. NonFlagArgs = []string{} // ConfigFile is the name of the config file actually loaded, specified by the // -config or -cfg command-line arg or the default file given in Config ConfigFile string // Help is variable target for -help or -h args Help bool )
var KiT_TestEnum = kit.Enums.AddEnum(TestEnumN, kit.NotBitFlag, nil)
This registers the enum with Kit which then allows full set / get from strings.
Functions ¶
func CommandArgs ¶
CommandArgs adds non-field args that control the config process: -config -cfg -help -h
func Config ¶
Config is the overall config setting function, processing config files and command-line arguments, in the following order:
- Apply any `def:` field tag default values.
- Look for `--config`, `--cfg`, or `-c` arg, specifying a config file on the command line.
- Fall back on default config file name passed to `Config` function, if arg not found.
- Read any `Include[s]` files in config file in deepest-first (natural) order, then the specified config file last.
- Process command-line args based on Config field names, with `.` separator for sub-fields.
- Boolean flags are set on with plain -flag; use No prefix to turn off (or explicitly set values to true or false).
Also processes -help or -h and prints usage and quits immediately.
func FieldArgNames ¶
FieldArgNames adds to given args map all the different ways the field names can be specified as arg flags, mapping to the reflect.Value
func IncludeStack ¶
IncludeStack returns the stack of include files in the natural order in which they are encountered (nil if none). Files should then be read in reverse order of the slice. Returns an error if any of the include files cannot be found on IncludePath. Does not alter cfg.
func LogFileName ¶
LogFileName returns a standard log file name as netName_runName_logName.tsv
func OpenFS ¶
OpenFS reads config from given TOML file, using the fs.FS filesystem -- e.g., for embed files.
func OpenWithIncludes ¶
OpenWithIncludes reads config from given config file, looking on IncludePaths for the file, and opens any Includes specified in the given config file in the natural include order so includee overwrites included settings. Is equivalent to Open if there are no Includes. Returns an error if any of the include files cannot be found on IncludePath.
func ParseArgs ¶
func ParseArgs(cfg any, args []string, allArgs map[string]reflect.Value, errNotFound bool) ([]string, error)
ParseArgs parses given args using map of all available args setting the value accordingly, and returning any leftover args. setting errNotFound = true causes args that are not in allArgs to trigger an error. Otherwise, it just skips those.
func SetArgValue ¶
SetArgValue sets given arg name to given value, into settable reflect.Value
func SetFromArgs ¶
SetFromArgs sets Config values from command-line args, based on the field names in the Config struct. Returns any args that did not start with a `-` flag indicator. For more robust error processing, it is assumed that all flagged args (-) must refer to fields in the config, so any that fail to match trigger an error. Errors can also result from parsing. Errors are automatically logged because these are user-facing.
func SetFromDefaults ¶
SetFromDefaults sets Config values from field tag `def:` values. Parsing errors are automatically logged.
Types ¶
type Includer ¶
type Includer interface { // IncludesPtr returns a pointer to the Includes []string field containing file(s) to include // before processing the current config file. IncludesPtr() *[]string }
Includer facilitates processing include files in Config objects.
type TestEnum ¶
type TestEnum int32
TestEnum is an enum type for testing
func (*TestEnum) FromString ¶
func (TestEnum) MarshalJSON ¶
func (TestEnum) MarshalText ¶
TOML uses Text interface