Documentation
¶
Overview ¶
Package config locates Nicely's folders and reads the shared and local config files, as the Configuration section of contract.md defines them.
Index ¶
Constants ¶
const Default = "default"
Default is the source of a value that no flag, variable, or file sets.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads the shared file, then the local file over it. A missing file is not an error. A table merges key by key across the files, and any other value, such as a list, replaces the one below it. Unknown keys come back for the CONFIG_UNKNOWN_KEY warning, so an older ncly reads a newer config.
Types ¶
type Config ¶
type Config struct {
Lang string `toml:"lang"`
}
Config holds the keys that this version of ncly knows. A zero value means the default applies.
type InvalidError ¶
InvalidError reports a config file with a syntax error or a value of the wrong type. Line is 0 when the parser does not say where.
func (*InvalidError) Error ¶
func (e *InvalidError) Error() string
func (*InvalidError) Unwrap ¶
func (e *InvalidError) Unwrap() error
type Key ¶
Key is a key of a config file that this version of ncly does not know. Table is true for a table, such as [skill], whose keys come after it.
type Paths ¶
type Paths struct {
Shared string
// Local is config.local.toml, beside Shared, for this machine only.
Local string
Data string
State string
Cache string
}
Paths locates Nicely's files and folders on this machine.
func Locate ¶
Locate resolves the paths from home and the environment. An XDG variable counts only when it holds an absolute path, as the XDG specification asks. NCLY_CONFIG names another shared file, and the local file moves beside it. Without an absolute home or XDG variable, default paths stay empty instead of resolving from the current folder.
type Value ¶ added in v0.18.0
type Value struct {
Key string `json:"key"`
Value any `json:"value"`
Source string `json:"source"`
}
Value is one resolved value with its source: a flag such as --lang, a variable such as NCLY_LANG, the path of the file that set it, or Default.
func Lang ¶ added in v0.18.0
Lang resolves the language with its source, in the order of Configuration in contract.md: the flag, NCLY_LANG, lang in the config files, LC_ALL, LC_MESSAGES, LANG, then en from Default. files reads the config only when no flag or NCLY_LANG sets the language, and returns nil when the files cannot be read.
type Values ¶ added in v0.18.0
Values holds every value of the config files by dotted key, such as skill.paths, each with the file that set it. A table with keys is no value of its own: each of its keys keeps its source. An empty table with no key beneath it is the value {} of its file.
func LoadValues ¶ added in v0.18.0
LoadValues reads the files as Load does, and keeps the source of each value: a table merges key by key, and any other value, an empty list included, keeps the file that replaced the one below it.
func (Values) Decode ¶ added in v0.18.0
Decode decodes the value at key, such as skill.paths, into target, a pointer to the type that the key holds, as Load decodes the keys of core. It returns the value with the file that set it, or one from Default that leaves target unchanged when no file sets key, such as under an empty table above key. A value of another type is an InvalidError about the file that set it, and so is a table at key, or a value where a table above key belongs.