Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@linkedapi/linkedin-cli",
"version": "1.2.24",
"version": "1.2.25",
"description": "AI-agent-friendly CLI for controlling LinkedIn accounts and retrieving real-time data.",
"author": "Linked API",
"license": "MIT",
Expand Down
25 changes: 17 additions & 8 deletions src/utils/split-list-flag.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { Errors } from '@oclif/core';

import { EXIT_CODE } from '@core/errors/exit-codes';

/**
* Splits a list flag into its values: comma-separated, or a JSON array of strings when the flag
* starts with `[`.
* Splits a list flag into its values: comma-separated, or a JSON array of strings when the flag is
* wrapped in `[` and `]`.
*
* The JSON form exists for values that contain a comma themselves – a "City, Region" location, an
* industry such as "Technology, Information and Internet", a company such as "Example Co., Ltd." –
* which a comma list would silently split into separate filters.
* which a comma list would silently split into separate filters. Only a value both starting with
* `[` and ending with `]` is read as JSON, so a literal such as "[24]7.ai" stays a plain value.
*/
export function splitListFlag(value: string): Array<string> {
const trimmedValue = value.trim();

if (!trimmedValue.startsWith('[')) {
return value.split(',').map((element) => element.trim());
if (!trimmedValue.startsWith('[') || !trimmedValue.endsWith(']')) {
return value.split(',').map((element): string => element.trim());
}

return parseJsonList(trimmedValue);
Expand All @@ -19,13 +24,17 @@ export function splitListFlag(value: string): Array<string> {
function parseJsonList(value: string): Array<string> {
const parsedValue = parseJson(value);

if (!Array.isArray(parsedValue) || !parsedValue.every((element) => typeof element === 'string')) {
throw new Error(
if (
!Array.isArray(parsedValue) ||
!parsedValue.every((element): boolean => typeof element === 'string')
) {
throw new Errors.CLIError(
`Invalid list value: ${value}. Expected comma-separated values or a JSON array of strings, e.g. '["Chicago, Illinois","Denver"]'`,
{ exit: EXIT_CODE.VALIDATION },
);
}

return parsedValue.map((element) => element.trim());
return parsedValue.map((element): string => element.trim());
}

function parseJson(value: string): unknown {
Expand Down
Loading