feat: add tag/endpoint selection mechanism
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import prompts from 'prompts';
|
||||
import { ApiKeyInfo } from './environment-finder';
|
||||
import { colors } from './logger';
|
||||
import type { TagSummary, SelectionFilter } from '../types';
|
||||
|
||||
function clearScreen(): void {
|
||||
process.stdout.write('\x1Bc');
|
||||
@@ -26,6 +27,70 @@ function printSummary(tags: string[], result: Record<string, string>): void {
|
||||
console.log(` ${'─'.repeat(54)}\n`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactively asks the user which tags and endpoints to generate.
|
||||
* Returns a SelectionFilter map of tag → selected operation nicknames.
|
||||
*/
|
||||
export async function askSelectionFilter(tagSummaries: TagSummary[]): Promise<SelectionFilter> {
|
||||
if (tagSummaries.length === 0) return {};
|
||||
|
||||
clearScreen();
|
||||
console.log(`\n ${colors.bright}📋 Selección de tags y endpoints${colors.reset}`);
|
||||
console.log(` ${'─'.repeat(54)}\n`);
|
||||
|
||||
// Step 1: select tags
|
||||
const tagResponse = await prompts({
|
||||
type: 'multiselect',
|
||||
name: 'tags',
|
||||
message: 'Tags a generar',
|
||||
choices: tagSummaries.map((t) => ({
|
||||
title: `${colors.bright}${t.tag}${colors.reset} ${colors.cyan}(${t.operations.length} endpoint${t.operations.length !== 1 ? 's' : ''})${colors.reset}`,
|
||||
value: t.tag,
|
||||
selected: true
|
||||
})),
|
||||
min: 1,
|
||||
hint: 'Espacio para marcar/desmarcar, Enter para confirmar'
|
||||
});
|
||||
|
||||
if (!tagResponse.tags?.length) process.exit(0);
|
||||
|
||||
const selectedTags: string[] = tagResponse.tags;
|
||||
const filter: SelectionFilter = {};
|
||||
|
||||
// Step 2: for each selected tag, select endpoints
|
||||
for (let i = 0; i < selectedTags.length; i++) {
|
||||
const tag = selectedTags[i];
|
||||
const summary = tagSummaries.find((t) => t.tag === tag)!;
|
||||
|
||||
clearScreen();
|
||||
console.log(
|
||||
`\n ${colors.bright}📋 Endpoints a generar${colors.reset} [${colors.cyan}${i + 1}${colors.reset} de ${colors.cyan}${selectedTags.length}${colors.reset}]`
|
||||
);
|
||||
console.log(` ${'─'.repeat(54)}\n`);
|
||||
|
||||
const opResponse = await prompts({
|
||||
type: 'multiselect',
|
||||
name: 'ops',
|
||||
message: `Tag ${colors.bright}${tag}${colors.reset}`,
|
||||
choices: summary.operations.map((op) => ({
|
||||
title:
|
||||
`${colors.bright}${op.method.padEnd(6)}${colors.reset} ${op.path}` +
|
||||
(op.summary ? ` ${colors.cyan}${op.summary}${colors.reset}` : ''),
|
||||
value: op.nickname,
|
||||
selected: true
|
||||
})),
|
||||
min: 1,
|
||||
hint: 'Espacio para marcar/desmarcar, Enter para confirmar'
|
||||
});
|
||||
|
||||
if (!opResponse.ops?.length) process.exit(0);
|
||||
|
||||
filter[tag] = opResponse.ops;
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactively asks the user which environment API key to use for each tag,
|
||||
* using arrow-key selection. The last option always allows typing manually.
|
||||
|
||||
Reference in New Issue
Block a user