config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config reads and writes commit-spark's configuration file (<UserConfigDir>/csp/config.toml).

The file is sparse: only keys the user explicitly set are stored. Load merges the file's values onto a caller-supplied set of defaults, so an absent key falls back to its default (this is how the OS-detected locale flows in). The package performs no OS locale detection itself, keeping it pure and testable.

Index

Constants

View Source
const (
	TypePlain        = "plain"
	TypeConventional = "conventional"
	TypeGitmoji      = "gitmoji"
)

Commit message format types accepted in the config file.

Variables

View Source
var Keys = []string{"model", "locale", "type", "timeout", "max-length"}

Keys are the recognized config keys, in display order.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns <UserConfigDir>/csp/config.toml.

func IsValidKey

func IsValidKey(key string) bool

IsValidKey reports whether key is a recognized config key.

func ParseType

func ParseType(v string) (string, error)

ParseType validates a commit message type (used for the --type flag). It returns the normalized value or a *apperr.UserError.

func ResolvedValue

func ResolvedValue(cfg Config, key string) (string, bool)

ResolvedValue returns the effective value of key as a display string. The second result is false for unrecognized keys.

func SetValues

func SetValues(path string, kvs []KV) error

SetValues validates and writes the given assignments to the config file. An empty value deletes the key (resetting it to its default). An unrecognized key returns a *apperr.UserError and no changes are written.

Types

type Config

type Config struct {
	Model     string
	Locale    string
	Type      string
	Timeout   time.Duration
	MaxLength int
}

Config is the fully resolved, validated configuration used at runtime.

func Default

func Default() Config

Default returns the static defaults. Locale is the ultimate fallback ("en"); the composition root overrides it with the OS-detected locale before Load.

func Load

func Load(path string, def Config) (Config, error)

Load reads the config file and merges its values onto def, validating each key that is present. Missing keys keep their default.

type Duration

type Duration time.Duration

Duration wraps time.Duration so it (un)marshals as a duration string such as "60s" or "500ms". A bare TOML integer (e.g. timeout = 60) fails to decode rather than being silently interpreted as nanoseconds.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText renders the duration in Go's canonical form (e.g. "1m0s").

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses a duration string via time.ParseDuration.

type KV

type KV struct {
	Key   string
	Value string
}

KV is a single key/value assignment for SetValues.

Jump to

Keyboard shortcuts

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