config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
var ErrNoConfig = errors.New("config file does not exist")

ErrNoConfig is returned by Load when the config file does not exist.

View Source
var ErrUnknownContext = errors.New("unknown context")

ErrUnknownContext is returned when a context name is not found.

Functions

func DefaultProjectFor

func DefaultProjectFor(cfg *Config, contextName string) (string, error)

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.

func Path

func Path() (string, error)

Path returns the resolved config file path, honoring XDG_CONFIG_HOME with a ~/.config fallback. It does not create the file or directory.

func Save

func Save(c *Config) error

Save atomically writes the config to disk with 0600 perms, creating the parent directory as needed.

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 Load

func Load() (*Config, error)

Load reads and decodes the config file. Returns ErrNoConfig if missing.

func (*Config) ActiveContext

func (c *Config) ActiveContext() (string, Context, error)

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

func (c *Config) AddContext(name string, ctx Context)

AddContext registers a new context. Overwrites if name already exists.

func (*Config) RemoveContext

func (c *Config) RemoveContext(name string) error

RemoveContext deletes a context. If it was current, clears current.

func (*Config) SetCurrentContext

func (c *Config) SetCurrentContext(name string) error

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).

type UI

type UI struct {
	Color  string `toml:"color"`  // auto|always|never
	Output string `toml:"output"` // table|json|yaml|csv
}

UI holds output/color preferences shared across contexts.

func DefaultUI

func DefaultUI() UI

DefaultUI returns sensible defaults for the UI block.

Jump to

Keyboard shortcuts

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