Documentation
¶
Overview ¶
Package config provides shared configuration primitives for the adaouat CLIs: a strict YAML loader, app-name-parameterized path resolution, and structured validation errors. Schemas, defaults, and merge semantics stay in the apps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyConfig = errors.New("config: empty config file")
ErrEmptyConfig is returned by Decode/Load when the input has no YAML document (an empty file), so callers can classify it with errors.Is instead of guessing from a raw "EOF".
Functions ¶
func Decode ¶
Decode strictly parses YAML from r into target (a pointer to a struct), rejecting unknown fields. Errors are prefixed "config:"; a yaml.TypeError is flattened into a single message joining each field-level error. An empty input returns ErrEmptyConfig.
func ExpandHome ¶ added in v0.19.3
ExpandHome replaces a leading "~" or "~/" with the user's home directory; any other path (including "~user/...") is returned unchanged, as is every path when the home directory cannot be determined.
Types ¶
type Resolver ¶
type Resolver struct {
App string
}
Resolver resolves an app's config file path from the standard precedence. App is the lowercase CLI name, e.g. "heraut" → HERAUT_FILE, .config/heraut.yml, .heraut.yml.
func (Resolver) InitDest ¶
InitDest returns where a new config should be written: .config/<app>.yml if a .config/ directory exists, else .<app>.yml.
func (Resolver) Label ¶
Label returns a human-readable description of a Source, for messages like "config loaded from X (from <label>)".
func (Resolver) Resolve ¶
Resolve returns the config path to use and the source that determined it:
- explicit (--config) if non-empty → FromFlag
- <APP>_FILE env var if set → FromEnv
- .config/<app>.yml if it exists → FromXDG
- .<app>.yml fallback → FromDefault
A leading "~" in the flag or env value is expanded via ExpandHome.
type ValidationError ¶
ValidationError describes a single semantic validation failure: the config Path that failed, a Message, and an optional remediation Hint.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors is a list of ValidationError that implements error.
func (ValidationErrors) Error ¶
func (ve ValidationErrors) Error() string