config

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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

func Load(p Paths) (Config, []Key, error)

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.

func Path added in v0.18.0

func Path(home, path string) (string, error)

Path resolves a path that a config file holds: an absolute path as is, and one that starts with ~/ from home. Any other path is an error, because its meaning would depend on the folder where ncly runs.

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

type InvalidError struct {
	File string
	Line int
	Err  error
}

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

type Key struct {
	File  string
	Name  string
	Table bool
}

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 is config.toml, the setup the user wants on every machine.
	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

func Locate(home string, lookupEnv func(string) (string, bool)) Paths

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

func Lang(flag string, getenv func(string) string, files func() Values) Value

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

type Values map[string]Value

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

func LoadValues(p Paths) (Values, error)

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

func (v Values) Decode(key string, target any) (Value, error)

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.

func (Values) Under added in v0.18.0

func (v Values) Under(key string) []Value

Under returns the values at key and beneath it, in the order of their keys, or one value of key from Default when no file sets any: a declared key such as agent.profiles covers every key beneath it.

Jump to

Keyboard shortcuts

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