cmd

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: 17 Imported by: 0

Documentation

Overview

Package cmd provides the CLI entry point for Spotnik via Cobra. It wires configuration, auth flow, theme loading, and application startup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAuthState

func CheckAuthState(cfg *config.Config, store keychain.TokenStore) (needsRegister, needsAuth bool)

CheckAuthState returns (needsRegister, needsAuth).

  • needsRegister: no client_id in config, or client_id fails format validation.
  • needsAuth: client_id is valid but no usable token is stored.

Exported for testing.

func EnsureAuthenticated

func EnsureAuthenticated(cfg *config.Config, store keychain.TokenStore, tokenBaseURL string) error

EnsureAuthenticated checks the token state and runs the auth flow if needed. The tokenBaseURL parameter allows tests to override the Spotify token endpoint. Pass "" for production (uses the real Spotify endpoint). Exported for testing.

func Execute

func Execute(version string)

Execute is the entry point called from main.go. version is injected at build time via LDFLAGS and forwarded into the root command's Version field and the TUI app options.

func HandleMissingClientID

func HandleMissingClientID() error

HandleMissingClientID prints setup instructions and returns an error. Exported for testing. The error signals the CLI to exit with code 1.

func LoadConfig

func LoadConfig(path string) (*config.Config, error)

LoadConfig reads the config file at path, bootstraps it if missing, and returns the parsed Config. An empty ClientID is not an error — the caller uses CheckAuthState to determine what flow is needed. Exported for testing.

func LogoutTokens

func LogoutTokens(store keychain.TokenStore) error

LogoutTokens removes all stored token keys from the token store. Exported for testing.

func PrintAuthLoginNoClientID

func PrintAuthLoginNoClientID(w io.Writer)

PrintAuthLoginNoClientID writes the "no client_id configured" error block to w. Exported for testing.

func PrintAuthStatus

func PrintAuthStatus(store keychain.TokenStore, configPath string, w io.Writer) error

PrintAuthStatus writes current auth + registration state to w. Always uses the standard CLI colour palette (not theme-dependent). Exported for testing.

func PrintExecuteError

func PrintExecuteError(w io.Writer, err error)

PrintExecuteError writes the styled error fallback block to w. Called by Execute() when a cobra subcommand returns an unhandled error. Exported for testing.

func PrintForgetSuccess

func PrintForgetSuccess(w io.Writer)

PrintForgetSuccess writes the styled "Session ended" confirmation block to w. Exported for testing.

func PrintLoginAuthFailure

func PrintLoginAuthFailure(w io.Writer, err error)

PrintLoginAuthFailure writes the "Authentication failed" error block for spotnik auth login to w. Exported for testing.

func PrintLogoutSuccess

func PrintLogoutSuccess(w io.Writer)

PrintLogoutSuccess writes the styled "Signed out" confirmation block to w. Exported for testing.

func PrintMissingClientIDInstructions

func PrintMissingClientIDInstructions(w io.Writer) error

PrintMissingClientIDInstructions writes setup instructions when client_id is missing. It directs the user to run `spotnik auth register`. Exported for testing.

func PrintReRegisterInstructions

func PrintReRegisterInstructions(w io.Writer, redirectURI string)

PrintReRegisterInstructions writes setup instructions for a user who is already registered (valid client_id present) but wants to register again with a new Client ID. Exported for testing.

func PrintRegisterAuthFailure

func PrintRegisterAuthFailure(w io.Writer, err error)

PrintRegisterAuthFailure writes the "Authorization failed" error block for spotnik auth register to w. Exported for testing.

func PrintRegisterInstructions

func PrintRegisterInstructions(w io.Writer, redirectURI string)

PrintRegisterInstructions writes the setup instructions block for spotnik auth register. redirectURI is the callback address derived from config (e.g. http://127.0.0.1:PORT/callback). The redirect URI is displayed on its own accent-coloured line below the numbered steps. Exported for testing.

func PrintSignedInLaunching

func PrintSignedInLaunching(w io.Writer)

PrintSignedInLaunching writes the "Signed in → Launching spotnik…" success pair to w. Exported for testing. Used by both runAuthLogin and runRegister.

func RootCommand

func RootCommand() *cobra.Command

RootCommand returns the root cobra command. Exported for testing.

func RunAuthFlow

func RunAuthFlow(cfg *config.Config, store keychain.TokenStore, tokenBaseURL string, w io.Writer) error

RunAuthFlow executes the full OAuth PKCE authorization flow. It generates PKCE credentials, starts the local callback server on cfg.CallbackPort, opens the browser, waits for the callback, and exchanges the code for tokens. The tokenBaseURL parameter allows tests to override the Spotify token endpoint. w receives progress output (URL block, step confirmations). Pass io.Discard for silent operation. Exported for testing.

func RunForget

func RunForget(store keychain.TokenStore, configPath string) error

RunForget clears tokens AND removes client_id from config at path. Exported for testing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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