Skip to content

spotify-cli


spotify-cli / output

output ​

Output helpers for the CLI.

Supports two modes: JSON (default, machine-parseable) and text (human-readable plaintext). The mode is set globally via setOutputMode().

Functions ​

getOutputMode() ​

getOutputMode(): OutputMode

Defined in: src/output.ts:27

Returns the current output mode.

Returns ​

OutputMode


handleError() ​

handleError(err): never

Defined in: src/output.ts:118

Top-level error handler that logs an error and exits the process.

If the error is a SpotifyCliError, its exit code and details are used. Otherwise the process exits with ExitCode.API.

Parameters ​

err ​

unknown

The caught error value.

Returns ​

never


logError() ​

logError(message, details?): void

Defined in: src/output.ts:99

Writes an error to stderr.

In text mode prints Error: <message>. In JSON mode writes a JSON object.

Parameters ​

message ​

string

Error message string.

details? ​

Record<string, unknown>

Optional additional context included in JSON output.

Returns ​

void


output() ​

output(data): void

Defined in: src/output.ts:83

Writes a value to stdout.

In JSON mode the value is JSON.stringify'd. In text mode the registered text formatter is used, falling back to a generic key-value flattener.

Parameters ​

data ​

unknown

Any value to output.

Returns ​

void


setOutputMode() ​

setOutputMode(mode): void

Defined in: src/output.ts:22

Sets the global output mode.

Parameters ​

mode ​

OutputMode

"json" for machine-parseable output, "text" for human-readable plaintext.

Returns ​

void


setTextFormatter() ​

setTextFormatter(fn): void

Defined in: src/output.ts:36

Registers a text formatter for the current command. Called by cli.ts before dispatching the command handler.

Parameters ​

fn ​

TextFormatter

Converts the output data to a human-readable string.

Returns ​

void

MIT Licensed. Not affiliated with or endorsed by Spotify AB.