Skip to content

Commit c44a2bc

Browse files
committed
lint:fix
1 parent 2173c63 commit c44a2bc

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

src/commands/api.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ function parseHeaders(raw: string | undefined): Record<string, string> {
106106
};
107107
}
108108

109+
const METHOD_COLORS: Record<string, (text: string) => string> = {
110+
GET: chalk.green,
111+
POST: chalk.yellow,
112+
PUT: chalk.blue,
113+
PATCH: chalk.cyan,
114+
DELETE: chalk.red,
115+
};
116+
117+
function formatEndpointLine(ep: Endpoint): string {
118+
const colorize = METHOD_COLORS[ep.method] || chalk.white;
119+
const methodStr = colorize(ep.method.padEnd(7));
120+
const summaryStr = ep.summary ? chalk.gray(` ${ep.summary}`) : '';
121+
return `${methodStr} ${ep.path}${summaryStr}`;
122+
}
123+
124+
const LIST_ENDPOINTS_HINT = `Run ${chalk.cyan('apify api --list-endpoints')} to see all available Apify API endpoints.`;
125+
126+
function printSuggestions(suggestions: Endpoint[]) {
127+
if (suggestions.length > 0) {
128+
simpleLog({ message: `\nDid you mean:`, stdout: false });
129+
130+
for (const ep of suggestions) {
131+
simpleLog({ message: ` ${formatEndpointLine(ep)}`, stdout: false });
132+
}
133+
}
134+
135+
simpleLog({ message: `\n${LIST_ENDPOINTS_HINT}`, stdout: false });
136+
}
137+
109138
export class ApiCommand extends ApifyCommand<typeof ApiCommand> {
110139
private cachedEndpoints: Endpoint[] | null = null;
111140

@@ -425,35 +454,6 @@ export class ApiCommand extends ApifyCommand<typeof ApiCommand> {
425454
}
426455
}
427456

428-
const METHOD_COLORS: Record<string, (text: string) => string> = {
429-
GET: chalk.green,
430-
POST: chalk.yellow,
431-
PUT: chalk.blue,
432-
PATCH: chalk.cyan,
433-
DELETE: chalk.red,
434-
};
435-
436-
function formatEndpointLine(ep: Endpoint): string {
437-
const colorize = METHOD_COLORS[ep.method] || chalk.white;
438-
const methodStr = colorize(ep.method.padEnd(7));
439-
const summaryStr = ep.summary ? chalk.gray(` ${ep.summary}`) : '';
440-
return `${methodStr} ${ep.path}${summaryStr}`;
441-
}
442-
443-
const LIST_ENDPOINTS_HINT = `Run ${chalk.cyan('apify api --list-endpoints')} to see all available Apify API endpoints.`;
444-
445-
function printSuggestions(suggestions: Endpoint[]) {
446-
if (suggestions.length > 0) {
447-
simpleLog({ message: `\nDid you mean:`, stdout: false });
448-
449-
for (const ep of suggestions) {
450-
simpleLog({ message: ` ${formatEndpointLine(ep)}`, stdout: false });
451-
}
452-
}
453-
454-
simpleLog({ message: `\n${LIST_ENDPOINTS_HINT}`, stdout: false });
455-
}
456-
457457
async function fetchEndpoints(): Promise<Endpoint[]> {
458458
let response: Response;
459459

0 commit comments

Comments
 (0)