yamlo

package
v0.4.135 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: ISC Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddYamlReferences

func AddYamlReferences(
	subPackageOptionData []pflags.OptionData,
	fieldPointerValues []interface{},
) (optionDataList []pflags.OptionData)

AddYamlReferences returns a pflags.OptionData slice of options to main

  • return value is appended to the pflags.OptionData list in main
  • filedPointerValues is a list of references to main’s y YamlData
  • subPackageOptionData is a list of options declared in subpackage

func ApplyYaml

func ApplyYaml(
	program, yamlFile, yamlDictionaryKey string, doYaml bool,
	genericYaml GenericYaml,
	optionData []pflags.OptionData,
) (err error)

ApplyYaml updates effective options with values read from a yaml file

  • program is app name “date” used to construct yaml file name
  • yamlFile is a specified file, or for empty string, a scan for files:
  • — filename: [program]-[hostname].yaml [program].yaml
  • — Directories: ~/apps .. /etc
  • — if a specified file is missing, that is error
  • — if no default file exists, or file was empty, no yaml options are loaded
  • yamlDictionaryKey is the key read form the top-level dictionary in yaml, empty string is default “options:”
  • genericYaml is a wrapper of unknown types
  • optionData is the list of options, containing pointers to effective option values
  • The top entry in the yaml file must be a dictionary
  • The value for yamlDictionaryKey must be a dictionary
  • the remainder of the yamlDictionaryKey is read when it matches the YamData struct
  • -verbose=yamlo.ApplyYaml “github.com/haraldrudell/parl/yamlo.ApplyYaml”

func FindFile

func FindFile(filename, program string) (readFilename string, byts []byte, err error)

FindFile locates and reads the yaml file

  • if filename is empty, try dirs: [~/app, .., /etc] files: [app-host.yaml, app.yaml]
  • readFilename is absolute, cleaned filename

Types

type GenericYaml added in v0.4.130

type GenericYaml interface {
	// Unmarshal updates [yamlo.Unmarshaler]’s value pointer with
	// data from yaml
	//	- yamlText is utf8-encoded binary data read from the yaml file
	//	- yamlDictionaryKey is the name of the top-level dictionary-key
	//		typically “options”
	//	- hasData indicates that unmarshal succeeded and yamlDictionaryKey
	//		was present
	Unmarshal(yamlText []byte, yamlDictionaryKey string) (hasData bool, err error)
	// VisitedReferencesMap returns a map of
	// key: any-typed pointers to fields of u.y,
	// value: lower-case field names
	// - unmarshals yaml again to an any object and then
	// builds the visited references map by comparing the unmarshaled object to the
	// u.y struct-pointer
	VisitedReferencesMap(yamlText []byte, yamlDictionaryKey string) (yamlVisistedReferences map[any]string, err error)
	// YDump returns field names and values for the yaml value struct
	YDump() (yamlVPrint string)
}

GenericYaml is a wrapper for yamlo.Unmarshaler that allows the yamlo package to unmarshal yaml to an unimported type

Jump to

Keyboard shortcuts

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