Documentation
¶
Overview ¶
Package cmd provides the CLI entry point for Spotnik via Cobra. It wires configuration, auth flow, theme loading, and application startup.
Index ¶
- func CheckAuthState(cfg *config.Config, store keychain.TokenStore) (needsRegister, needsAuth bool)
- func EnsureAuthenticated(cfg *config.Config, store keychain.TokenStore, tokenBaseURL string) error
- func Execute(version string)
- func HandleMissingClientID() error
- func LoadConfig(path string) (*config.Config, error)
- func LogoutTokens(store keychain.TokenStore) error
- func PrintAuthLoginNoClientID(w io.Writer)
- func PrintAuthStatus(store keychain.TokenStore, configPath string, w io.Writer) error
- func PrintExecuteError(w io.Writer, err error)
- func PrintForgetSuccess(w io.Writer)
- func PrintLoginAuthFailure(w io.Writer, err error)
- func PrintLogoutSuccess(w io.Writer)
- func PrintMissingClientIDInstructions(w io.Writer) error
- func PrintReRegisterInstructions(w io.Writer, redirectURI string)
- func PrintRegisterAuthFailure(w io.Writer, err error)
- func PrintRegisterInstructions(w io.Writer, redirectURI string)
- func PrintSignedInLaunching(w io.Writer)
- func RootCommand() *cobra.Command
- func RunAuthFlow(cfg *config.Config, store keychain.TokenStore, tokenBaseURL string, ...) error
- func RunForget(store keychain.TokenStore, configPath string) error
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 ¶
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 ¶
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 ¶
PrintAuthLoginNoClientID writes the "no client_id configured" error block to w. Exported for testing.
func PrintAuthStatus ¶
PrintAuthStatus writes current auth + registration state to w. Always uses the standard CLI colour palette (not theme-dependent). Exported for testing.
func PrintExecuteError ¶
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 ¶
PrintForgetSuccess writes the styled "Session ended" confirmation block to w. Exported for testing.
func PrintLoginAuthFailure ¶
PrintLoginAuthFailure writes the "Authentication failed" error block for spotnik auth login to w. Exported for testing.
func PrintLogoutSuccess ¶
PrintLogoutSuccess writes the styled "Signed out" confirmation block to w. Exported for testing.
func PrintMissingClientIDInstructions ¶
PrintMissingClientIDInstructions writes setup instructions when client_id is missing. It directs the user to run `spotnik auth register`. Exported for testing.
func PrintReRegisterInstructions ¶
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 ¶
PrintRegisterAuthFailure writes the "Authorization failed" error block for spotnik auth register to w. Exported for testing.
func PrintRegisterInstructions ¶
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 ¶
PrintSignedInLaunching writes the "Signed in → Launching spotnik…" success pair to w. Exported for testing. Used by both runAuthLogin and runRegister.
func RootCommand ¶
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.
Types ¶
This section is empty.