config

package
v0.1.0-rc3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config handles loading and providing application configuration. Config is read from ~/.config/spotnik/config.toml at startup.

Index

Constants

This section is empty.

Variables

View Source
var ThemeValidator func(id string) bool

ThemeValidator is an optional function that reports whether a theme ID is valid. It is set by the caller (cmd/root.go) at startup to avoid an import cycle between config and ui/theme. When nil, only the empty-string check is applied.

Swappable for testing: set to a function that knows the valid IDs.

Functions

func Bootstrap

func Bootstrap(path string) error

Bootstrap creates the config file at path with a default template if it does not already exist. Creates the parent directory if needed. If the file already exists, Bootstrap appends any missing config sections so that pre-feature-13 users always have every required section after upgrade.

func ClearClientID

func ClearClientID(path string) error

ClearClientID removes any line whose trimmed content starts with "client_id" from the config file at path, then writes the result back. The [spotify] section header and all other keys (callback_port, preferences, etc.) are preserved. Returns an error if the file cannot be read or written.

func DefaultConfigPath

func DefaultConfigPath() string

DefaultConfigPath returns the default config file path. It is ~/.config/spotnik/config.toml on all platforms.

func SetClientID

func SetClientID(path string, clientID string) error

SetClientID writes or updates the client_id key in the config file at path. Three cases are handled:

  • client_id line already exists → replace it in-place
  • [spotify] section exists but no client_id → insert after the [spotify] header
  • Neither exists → append "\n[spotify]\nclient_id = "..."\n"

If the file does not exist, it is created (along with its parent directory).

func ValidateClientID

func ValidateClientID(s string) error

ValidateClientID enforces the Spotify client ID shape: exactly 32 hexadecimal characters (after trimming whitespace). Used by both the CLI prompt and the TUI onboarding step to reject malformed IDs before writing to config.

Types

type CLIConfig

type CLIConfig struct {
	// Palette controls how CLI output colours are resolved.
	// Valid values: "auto", "fixed", "theme".
	// Empty or unrecognised values are clamped to "auto" on load.
	Palette string `toml:"palette"`
}

CLIConfig holds CLI-specific settings.

type Config

type Config struct {
	// ClientID is the Spotify application client ID.
	// May be empty if not set in config — user must provide it via onboarding.
	ClientID string

	// CallbackPort is the port the OAuth callback server listens on.
	// Defaults to 8888. Register http://127.0.0.1:<port>/callback in the
	// Spotify Developer Dashboard exactly once — it never changes between launches.
	CallbackPort int

	Preferences PreferencesConfig `toml:"preferences"`
	CLI         CLIConfig         `toml:"cli"`
	UI          UIConfig          `toml:"ui"`
}

Config holds all application configuration.

func Default

func Default() *Config

Default returns a Config populated with sensible defaults.

func Load

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

Load reads the config file at the given path and returns a populated Config. If the file does not exist, Load returns Default() with no error. Empty ClientID is not an error — the caller handles the embedded fallback. If the TOML is malformed, Load returns a parse error with file path context. Invalid preference values are clamped: negative Preset/Visualizer → 0, unknown theme → "black".

type PreferencesConfig

type PreferencesConfig struct {
	// Theme is the config key for the active colour theme.
	// Valid values: "black", "monokai", "catppuccin", "nord", "light", etc.
	// Defaults to "black" if unset or unknown.
	Theme string `toml:"theme"`

	// Preset is the Page A layout preset index (0-based).
	// Negative values are clamped to 0 on load.
	Preset int `toml:"preset"`

	// Visualizer is the visualizer pattern index (0-6).
	// Negative values are clamped to 0 on load.
	Visualizer int `toml:"visualizer"`
}

PreferencesConfig holds user-facing preference settings.

type UIConfig

type UIConfig struct {
	// Glyphs controls whether unicode or ASCII glyphs are used in the TUI.
	// Valid values: "auto" (default), "unicode", "ascii".
	// "auto" inspects LC_ALL/LC_CTYPE/LANG for a UTF-8 marker.
	Glyphs string `toml:"glyphs"`
}

UIConfig holds TUI rendering preferences.

func (*UIConfig) Validate

func (c *UIConfig) Validate() error

Validate returns an error if any UIConfig field contains an invalid value.

Jump to

Keyboard shortcuts

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