cli

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package cli wires up the command tree.

Index

Constants

View Source
const (
	ExitOK        = 0
	ExitError     = 1
	ExitUsage     = 2
	ExitAuth      = 4
	ExitNotFound  = 5
	ExitForbidden = 6
	ExitRateLimit = 7
)

Exit codes. Anything the user can act on gets its own code so scripts can branch without parsing stderr.

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(w io.Writer, styles fang.Styles, err error)

ErrorHandler renders an error the way fang does, but without destroying its formatting.

fang's DefaultErrorHandler runs the message through a style whose Transform is titleFirstWord, which is `strings.Fields` followed by `Join(" ")`. That collapses every newline, so a message built as "what went wrong\n\nwhat to do about it" arrives as one run-on line — and it title-cases the first word, turning `--limit` into `--Limit` and a quoted id like "pl_new" into "Pl_new".

Both matter here because the errors in this package are written to be read: a cause, a blank line, then the fix. So: keep fang's header and colours, drop the transform, and capitalise only where it cannot corrupt an identifier.

func ExitCodeFor

func ExitCodeFor(err error) int

ExitCodeFor maps an error to the process exit code. It lives here rather than in main so that tests assert against the same mapping the binary uses.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd builds the command tree. Version is injected by main.

Types

type AuthError

type AuthError struct{ Err error }

AuthError means credentials are missing or rejected. It maps to ExitAuth.

func (AuthError) Error

func (e AuthError) Error() string

func (AuthError) Unwrap

func (e AuthError) Unwrap() error

type ForbiddenError

type ForbiddenError struct{ Err error }

ForbiddenError means the token is valid but the call is not permitted — a missing scope, or an account outside a Development Mode app's authorised users. It is kept apart from AuthError because signing in again does not fix it.

func (ForbiddenError) Error

func (e ForbiddenError) Error() string

func (ForbiddenError) Unwrap

func (e ForbiddenError) Unwrap() error

type NotFoundError

type NotFoundError struct{ Err error }

NotFoundError means the thing the user named does not exist.

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Unwrap

func (e NotFoundError) Unwrap() error

type RateLimitError

type RateLimitError struct{ Err error }

RateLimitError means Spotify throttled the request and the retries ran out.

func (RateLimitError) Error

func (e RateLimitError) Error() string

func (RateLimitError) Unwrap

func (e RateLimitError) Unwrap() error

type UsageError

type UsageError struct{ Err error }

UsageError marks an error as the user holding the tool wrong, rather than something going wrong at runtime. It maps to ExitUsage.

func (UsageError) Error

func (e UsageError) Error() string

func (UsageError) Unwrap

func (e UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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