spotify-cli / parse
parse
Utility parsers for CLI argument values.
Functions
ensureTrackUri()
ensureTrackUri(
id):string
Defined in: src/parse.ts:55
Ensures a string is a full Spotify track URI. If the input already starts with spotify:, it is returned as-is. Otherwise it is treated as a bare track ID and prefixed with spotify:track:.
Parameters
id
string
Returns
string
extractId()
extractId(
input):string
Defined in: src/parse.ts:73
Extracts a Spotify ID from user input that may be a full URI or a bare ID. For detail/read commands that take a single <id> argument.
Parameters
input
string
Returns
string
loadVariadicInputs()
loadVariadicInputs(
positional,flags,options?):string[]
Defined in: src/parse.ts:107
Loads a list of inputs (URIs, IDs, or search queries) from a combination of positional args, a file flag, and stdin.
- Positional
-is a sentinel meaning "read from stdin" (consumed at most once). flags[fileFlag](default"uris-file") names a file to read line-by-line.- File and stdin lines are trimmed; blank lines and
#-prefixed comments are skipped.
Inputs from all three sources are concatenated in this order: positional, then file. The stdin contents are inserted at the position of the - sentinel.
Parameters
positional
string[]
Positional args after consuming any leading IDs (e.g. playlist id).
flags
Record<string, string>
Parsed flags record; only flags[fileFlag] is consulted.
options?
Optional override of the file flag name and stdin behavior.
allowStdin?
boolean
fileFlag?
string
Returns
string[]
Combined list of non-empty input strings.
optionalIntFlag()
optionalIntFlag(
flags,name):number|undefined
Defined in: src/parse.ts:34
Reads an optional integer flag from a flags record.
Returns undefined when the flag is absent or empty, otherwise delegates to parseIntFlag.
Parameters
flags
Record<string, string>
The parsed flags record from CLI args.
name
string
The flag name (without -- prefix).
Returns
number | undefined
The parsed integer, or undefined if not provided.
parseIntFlag()
parseIntFlag(
value,name):number
Defined in: src/parse.ts:18
Parses a string as a base-10 integer or throws an argsError.
Parameters
value
string
The raw string value to parse.
name
string
Display name used in the error message (e.g. "--limit").
Returns
number
The parsed integer.
Throws
SpotifyCliError if the value is not a valid integer.
requireIds()
requireIds(
positional,usage):string[]
Defined in: src/parse.ts:59
Parameters
positional
string[]
usage
string
Returns
string[]
