Go API documentation
github.com/rotari-dev/rotari/internal/config
Overview
package config // import "github.com/rotari-dev/rotari/internal/config"
Package config finds and parses rotari's config files.
A config file is config.yaml, config.toml, or config.json in the global config
directory, a base directory, or a project directory. This package owns where
those files are looked for, which scope applies, and how each format is parsed.
What the keys mean (CLI option defaults) and the config template belong to
cmd/rotari.
Constants
const WorkspaceFile = ".rotari.toml"
Variables
var Warnf = func(format string, args ...any) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
}
Warnf reports a config file that cannot be inspected, read, or parsed; such
a file is skipped or treated as empty. It writes to stderr unless replaced.
Functions
func EffectivePath(baseDir, projectName string) string
EffectivePath returns the legacy single-file config location. New callers
should use Load to enumerate and merge all scopes.
func FilePaths(directory string) []string
FilePaths returns the config files that exist in directory.
func GlobalPath() string
GlobalPath returns the global config file, or "" when there is none.
func HomeDir() (string, error)
HomeDir returns the global config directory: $XDG_CONFIG_HOME/rotari,
or ~/.config/rotari.
func ListPaths(baseDir, projectName string, additionalNames ...string) (common []string, projects map[string][]string)
ListPaths returns every config file found across all scopes for `config
--list`. additionalNames are other config filenames to include, such as
notifications.toml. Unlike PathsForRun, it does not stop at the first scope
that has files: --list is meant to show the user everything, not just the
one scope that would take effect.
func LoadFile(directory string) (map[string]any, error)
LoadFile parses the config file in directory, or returns an empty config
when there is none. More than one config file there is an error.
func LoadPath(path string) (map[string]any, error)
LoadPath parses the config file at path.
func Marshal(values map[string]any) ([]byte, error)
Marshal produces canonical TOML from file values only.
func Merge(lower, higher map[string]any) map[string]any
Merge makes an independent deep copy. Maps recurse, arrays replace, and null
is unspecified; false, zero and empty strings are retained.
func Parse(path string, data []byte) (map[string]any, error)
Parse parses config data in the format that path's extension names.
func PathsForRun(baseDir, projectName string) []string
PathsForRun preserves legacy single-scope lookup for historical records:
project, then baseDir, then global. New runs use Loaded.Snapshot instead.
func Validate(scope, path string, values map[string]any) error
Validate prevents location cycles, including command-specific location keys.
Types
type Loaded struct {
Values map[string]any
Sources []Source
}
Loaded holds file values captured once, independently of runtime overrides.
func Load(cwd, baseDir, projectName string) (Loaded, error)
Load reads all ordinary scopes; cwd is explicitly supplied by the caller.
A Web server captures it at startup and never substitutes a job's cwd.
func LoadScope(scope, directory string) (Loaded, error)
LoadScope loads at most one file, failing on invalid discovered files.
func (loaded *Loaded) Add(layer Loaded)
func (loaded Loaded) Snapshot() (*model.FileConfigSnapshot, error)
type Source = model.ConfigSource
Source identifies a real configuration file, not a synthesized view.