config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and writes the fdb YAML config file (default location: ~/.fdb/config.yaml) using protoconfig. The file is structured as a `fdb.config.v1.Config` message — proto-backed so the schema is versioned and forwards-compatible.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoContext = errors.New("context not found")

ErrNoContext is returned by ResolveContext when the selected context does not exist in the loaded config.

Functions

func Load

func Load() (*configv1.Config, error)

Load is a convenience wrapper over LoadFrom that uses Path().

func LoadFrom

func LoadFrom(path string) (*configv1.Config, error)

LoadFrom reads the YAML file at path and returns the parsed Config. A missing file is not an error — protoconfig.Optional() makes the YAML source soft, so first-run commands (like `config use-context`) can operate on a zero value and then write back.

func Path

func Path() (string, error)

Path returns the effective config path — FDB_CONFIG env var if set, else ~/.fdb/config.yaml.

func ResolveContext

func ResolveContext(cfg *configv1.Config, name string) (*configv1.Context, error)

ResolveContext looks up a named context in the config. An empty name resolves Config.current_context. Returns ErrNoContext if the name is empty and no current context is set, or if the named context is absent.

func Save

func Save(cfg *configv1.Config) error

Save is a convenience wrapper over SaveTo that uses Path().

func SaveTo

func SaveTo(path string, cfg *configv1.Config) error

SaveTo writes the Config to path as YAML, creating parent directories as needed. The existing file is atomically replaced via a temp file + rename, so a crash mid-write cannot leave a truncated config.

func SetCurrentContext

func SetCurrentContext(name string) error

SetCurrentContext rewrites ONLY the `current_context` scalar in the on-disk YAML, preserving every comment and all formatting. A Load→mutate→Save round-trip re-marshals through proto and destroys comments — including the guidance block `config init` just wrote — so the single-field update edits the YAML AST instead (RFC-174 Slice 5). A missing file degrades to a minimal document.

Types

type ContextNotFoundError

type ContextNotFoundError struct {
	Name string
}

ContextNotFoundError identifies a selected context that is absent from the config.

func (*ContextNotFoundError) Error

func (e *ContextNotFoundError) Error() string

func (*ContextNotFoundError) Unwrap

func (e *ContextNotFoundError) Unwrap() error

Jump to

Keyboard shortcuts

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