Skip to content

Commit

Permalink
chore(scripts): remove interactive option (#2515)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jan 11, 2024
1 parent c63fe27 commit d8dc933
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 203 deletions.
42 changes: 13 additions & 29 deletions scripts/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ALL,
getClientChoices,
generatorList,
prompt,
transformSelection,
PROMPT_CLIENTS,
PROMPT_LANGUAGES,
} from './utils.js';
Expand All @@ -37,10 +37,6 @@ const flags = {
flag: '-v, --verbose',
description: 'make the generation verbose',
},
interactive: {
flag: '-i, --interactive',
description: 'open prompt to query parameters',
},
skipCache: {
flag: '-s, --skip-cache',
description: 'skip cache checking to force building specs',
Expand All @@ -59,12 +55,10 @@ program
.addArgument(args.language)
.addArgument(args.clients)
.option(flags.verbose.flag, flags.verbose.description)
.option(flags.interactive.flag, flags.interactive.description)
.action(async (langArg: LangArg, clientArg: string[], { verbose, interactive }) => {
const { language, client, clientList } = await prompt({
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
const { language, client, clientList } = transformSelection({
langArg,
clientArg,
interactive,
});

setVerbose(Boolean(verbose));
Expand All @@ -80,12 +74,10 @@ buildCommand
.addArgument(args.language)
.addArgument(args.clients)
.option(flags.verbose.flag, flags.verbose.description)
.option(flags.interactive.flag, flags.interactive.description)
.action(async (langArg: LangArg, clientArg: string[], { verbose, interactive }) => {
const { language, client, clientList } = await prompt({
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
const { language, client, clientList } = transformSelection({
langArg,
clientArg,
interactive,
});

setVerbose(Boolean(verbose));
Expand All @@ -98,14 +90,12 @@ buildCommand
.description('Build a specified spec')
.addArgument(args.clients)
.option(flags.verbose.flag, flags.verbose.description)
.option(flags.interactive.flag, flags.interactive.description)
.option(flags.skipCache.flag, flags.skipCache.description)
.option(flags.outputType.flag, flags.outputType.description)
.action(async (clientArg: string[], { verbose, interactive, skipCache, outputJson }) => {
const { client, clientList } = await prompt({
.action(async (clientArg: string[], { verbose, skipCache, outputJson }) => {
const { client, clientList } = transformSelection({
langArg: ALL,
clientArg,
interactive,
});

setVerbose(Boolean(verbose));
Expand All @@ -124,12 +114,10 @@ ctsCommand
.addArgument(args.language)
.addArgument(args.clients)
.option(flags.verbose.flag, flags.verbose.description)
.option(flags.interactive.flag, flags.interactive.description)
.action(async (langArg: LangArg, clientArg: string[], { verbose, interactive }) => {
const { language, client, clientList } = await prompt({
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
const { language, client, clientList } = transformSelection({
langArg,
clientArg,
interactive,
});

setVerbose(Boolean(verbose));
Expand All @@ -142,12 +130,10 @@ ctsCommand
.description('Run the tests for the CTS')
.addArgument(args.language)
.option(flags.verbose.flag, flags.verbose.description)
.option(flags.interactive.flag, flags.interactive.description)
.action(async (langArg: LangArg, { verbose, interactive }) => {
const { language } = await prompt({
.action(async (langArg: LangArg, { verbose }) => {
const { language } = transformSelection({
langArg,
clientArg: [ALL],
interactive,
});

setVerbose(Boolean(verbose));
Expand All @@ -160,12 +146,10 @@ program
.description('Run the playground')
.addArgument(args.language)
.addArgument(args.client)
.option(flags.interactive.flag, flags.interactive.description)
.action(async (langArg: LangArg, cliClient: string, { interactive }) => {
const { language, client } = await prompt({
.action(async (langArg: LangArg, cliClient: string) => {
const { language, client } = transformSelection({
langArg,
clientArg: [cliClient],
interactive,
});

setVerbose(true);
Expand Down
59 changes: 12 additions & 47 deletions scripts/cli/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import inquirer from 'inquirer';

import { CLIENTS, GENERATORS, LANGUAGES } from '../common.js';
import type { Generator, Language } from '../types.js';

Expand All @@ -10,16 +8,15 @@ export const PROMPT_CLIENTS = [ALL, ...CLIENTS];
export type AllLanguage = Language | typeof ALL;
export type LangArg = AllLanguage | undefined;

type PromptDecision = {
type Selection = {
language: AllLanguage;
client: string[];
clientList: string[];
};

type Prompt = {
type Args = {
langArg: LangArg;
clientArg: string[];
interactive: boolean;
};

export function getClientChoices(language?: LangArg, clientList = PROMPT_CLIENTS): string[] {
Expand Down Expand Up @@ -47,60 +44,28 @@ export function generatorList({
.filter(Boolean);
}

export async function prompt({ langArg, clientArg, interactive }: Prompt): Promise<PromptDecision> {
const decision: PromptDecision = {
export function transformSelection({ langArg, clientArg }: Args): Selection {
const selection: Selection = {
client: [ALL],
language: ALL,
language: langArg || ALL,
clientList: [],
};

if (!langArg) {
if (interactive) {
const { language } = await inquirer.prompt<PromptDecision>([
{
type: 'list',
name: 'language',
message: 'Select a language',
default: ALL,
choices: LANGUAGES,
},
]);

decision.language = language;
}
} else {
decision.language = langArg;
}

decision.clientList = getClientChoices(decision.language, CLIENTS);

if (!clientArg?.length) {
if (interactive) {
const { client } = await inquirer.prompt<{ client: string }>([
{
type: 'list',
name: 'client',
message: 'Select a client',
default: ALL,
choices: getClientChoices(decision.language),
},
]);
selection.clientList = getClientChoices(selection.language, CLIENTS);

decision.client = [client];
}
} else {
if (clientArg?.length) {
clientArg.forEach((client) => {
if (![ALL, ...decision.clientList].includes(client)) {
if (![ALL, ...selection.clientList].includes(client)) {
throw new Error(
`The '${clientArg}' client does not exist for ${
decision.language
}.\n\nAllowed choices are: ${decision.clientList.join(', ')}`
selection.language
}.\n\nAllowed choices are: ${selection.clientList.join(', ')}`
);
}
});

decision.client = clientArg;
selection.client = clientArg;
}

return decision;
return selection;
}
2 changes: 0 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@octokit/rest": "20.0.2",
"@types/folder-hash": "4.0.4",
"@types/fs-extra": "11.0.4",
"@types/inquirer": "9.0.7",
"@types/js-yaml": "4.0.9",
"@types/micromatch": "4.0.6",
"@types/node": "20.10.6",
Expand All @@ -42,7 +41,6 @@
"execa": "8.0.1",
"folder-hash": "4.0.4",
"fs-extra": "11.2.0",
"inquirer": "9.2.12",
"js-yaml": "4.1.0",
"knip": "3.12.0",
"micromatch": "4.0.5",
Expand Down
7 changes: 3 additions & 4 deletions website/docs/contributing/CLI/clients-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ apic generate <language | all> <client... | all>

### Available options

| Option | Command | Description |
|-------------|:------------------|:--------------------------------------------------------------|
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |
| interactive | -i, --interactive | Open prompt to query parameters |
| Option | Command | Description |
|---------|:--------------|:--------------------------------------------------------------|
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |

## Generate

Expand Down
7 changes: 3 additions & 4 deletions website/docs/contributing/CLI/cts-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ apic cts generate <language | all> <client... | all>

### Available options

| Option | Command | Description |
|-------------|:------------------|:--------------------------------------------------------------|
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |
| interactive | -i, --interactive | Open prompt to query parameters |
| Option | Command | Description |
|---------|:--------------|:--------------------------------------------------------------|
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |

## Generate

Expand Down
9 changes: 4 additions & 5 deletions website/docs/contributing/CLI/specs-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ apic build specs <client... | all>

### Available options

| Option | Command | Description |
| ----------- | :---------------- | :------------------------------------------------------------ |
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |
| interactive | -i, --interactive | Open prompt to query parameters |
| skip cache | -s, --skip-cache | Skip cache checking to force building specs |
| Option | Command | Description |
|------------|:-----------------|:--------------------------------------------------------------|
| verbose | -v, --verbose | Make the process verbose, display logs from third party tools |
| skip cache | -s, --skip-cache | Skip cache checking to force building specs |

## Build

Expand Down
Loading

0 comments on commit d8dc933

Please sign in to comment.