config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config loads, saves, and validates lore's TOML config file.

On-disk paths are stored with `~/` so the file is portable across machines (e.g. synced via dotfiles). In-memory Config always holds absolute paths; expansion happens once at Load and Save handles contraction on the way out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contract

func Contract(p string) string

Contract is the inverse of Expand: if p is under HOME, rewrite the prefix back to `~`. Otherwise returns p unchanged. Best-effort: on any error determining HOME, returns p unchanged.

func DefaultConfigTOML

func DefaultConfigTOML() []byte

DefaultConfigTOML returns the embedded commented template byte-for-byte. Used by callers (tests, future `lore reset` etc.) that need the raw file.

func Expand

func Expand(p string) (string, error)

Expand resolves a leading `~/` to the user's home directory. A bare `~` also expands. Returns p unchanged if it doesn't start with `~`.

func Path

func Path() (string, error)

Path returns the on-disk location of the config file. Honors XDG_CONFIG_HOME; falls back to ~/.config/lore/config.toml.

func Save

func Save(cfg Config) error

Save writes cfg to disk. Path fields are contracted back to `~/...` form. Comments from the embedded template are NOT preserved; this round-trip path is for programmatic config edits in later slices. Slice 1 uses WriteDefaults to lay down the commented template instead.

func WriteDefaults

func WriteDefaults() error

WriteDefaults writes the embedded commented template verbatim to the config file location. Returns CodeConflict if the file already exists; the caller is responsible for the higher-level "already configured" check.

On any failure after the file is opened (write error, sync error), the partial file is removed so a retry isn't permanently blocked by the O_EXCL guard. ENOSPC mid-write is the motivating real-world case.

Types

type CommitConfig

type CommitConfig struct {
	Auto         bool   `toml:"auto"`
	AddTemplate  string `toml:"add_template"`
	RmTemplate   string `toml:"rm_template"`
	MvTemplate   string `toml:"mv_template"`
	SyncTemplate string `toml:"sync_template"`
}

CommitConfig holds commit-related preferences.

type Config

type Config struct {
	CentralRepo   string       `toml:"central_repo"`
	ProjectsRoots []string     `toml:"projects_roots"`
	ProjectsDepth int          `toml:"projects_root_depth"`
	AgentDirs     []string     `toml:"agent_dirs"`
	Commit        CommitConfig `toml:"commit"`
}

Config is the typed representation of ~/.config/lore/config.toml.

func Defaults

func Defaults() Config

Defaults returns the in-memory Config with all defaults applied and path fields expanded to absolute paths.

func Load

func Load() (cfg Config, exists bool, err error)

Load reads the config file, fills in any missing keys from defaults, and expands `~/` in path fields. If the file doesn't exist, returns Defaults() with exists=false (and a nil error).

Jump to

Keyboard shortcuts

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