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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Load ¶
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.