Documentation
¶
Overview ¶
Package config provides TOML-backed configuration storage for the finna CLI. It mirrors the kubectl-style "contexts" model: multiple named servers, one active at a time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoConfig = errors.New("config file does not exist")
ErrNoConfig is returned by Load when the config file does not exist.
var ErrUnknownContext = errors.New("unknown context")
ErrUnknownContext is returned when a context name is not found.
Functions ¶
func DefaultProjectFor ¶
DefaultProjectFor returns the default_project slug for the named context. Returns ("", nil) when no default is set. Returns ErrUnknownContext when the context does not exist.
Types ¶
type Config ¶
type Config struct {
CurrentContext string `toml:"current_context,omitempty"`
Contexts map[string]Context `toml:"contexts,omitempty"`
UI UI `toml:"ui"`
}
Config is the root TOML schema persisted at ~/.config/finna/config.toml.
func (*Config) ActiveContext ¶
ActiveContext returns the currently selected context together with its name. Returns ErrUnknownContext if no context is active or the named one is missing. (Named ActiveContext to avoid collision with the CurrentContext field; the spec name is preserved on the field for TOML compatibility.)
func (*Config) AddContext ¶
AddContext registers a new context. Overwrites if name already exists.
func (*Config) RemoveContext ¶
RemoveContext deletes a context. If it was current, clears current.
func (*Config) SetCurrentContext ¶
SetCurrentContext switches the active context. Returns ErrUnknownContext if the name is not registered.
type Context ¶
type Context struct {
Server string `toml:"server"`
Insecure bool `toml:"insecure,omitempty"`
DefaultProject string `toml:"default_project,omitempty"`
}
Context represents a single backend target (server URL + per-context preferences). Tokens are never stored here; they live in the OS keyring.
type Effective ¶
type Effective struct {
ContextName string
Server string
Output string
Color string
Debug bool
DefaultProject string
}
Effective holds resolved CLI runtime settings after applying the flag > env > file > default precedence chain.
func Resolve ¶
func Resolve(cfg *Config, flagContext, flagServer, flagOutput string, flagNoColor, flagDebug bool) Effective
Resolve combines a loaded config with CLI flag overrides and process environment to produce the Effective settings. The flag values represent what the user passed on the command line (empty string == not set).