From 8bad374899fdbcf0c778009decd2fce45585dfab Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Fri, 21 Feb 2025 13:52:56 +0000 Subject: [PATCH] chore(cli): don't emit empty user input interfaces --- .../user-input-gen/lib/user-input-gen.ts | 73 ++++++++++--------- packages/aws-cdk/lib/cli/user-input.ts | 10 +-- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/packages/@aws-cdk/user-input-gen/lib/user-input-gen.ts b/packages/@aws-cdk/user-input-gen/lib/user-input-gen.ts index 57512fd3..94106df0 100644 --- a/packages/@aws-cdk/user-input-gen/lib/user-input-gen.ts +++ b/packages/@aws-cdk/user-input-gen/lib/user-input-gen.ts @@ -65,46 +65,53 @@ export async function renderUserInputType(config: CliConfig): Promise { // add command-specific options for (const [commandName, command] of Object.entries(config.commands)) { - const commandType = new StructType(scope, { - export: true, - name: `${kebabToPascal(commandName)}Options`, - docs: { - summary: command.description, - remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined, - }, - }); - - // add command level options - for (const [optionName, option] of Object.entries(command.options ?? {})) { - commandType.addProperty({ - name: kebabToCamelCase(optionName), - type: convertType(option.type, option.count), + let commandType: Type = Type.anonymousInterface([]); + const commandOptions = Object.entries(command.options ?? {}); + + // if we have something to add to an interface + if (command.arg || commandOptions.length) { + const commandStruct = new StructType(scope, { + export: true, + name: `${kebabToPascal(commandName)}Options`, docs: { - // Notification Arns is a special property where undefined and [] mean different things - default: optionName === 'notification-arns' ? 'undefined' : normalizeDefault(option.default), - summary: option.desc, - deprecated: option.deprecated ? String(option.deprecated) : undefined, - remarks: option.alias ? `aliases: ${Array.isArray(option.alias) ? option.alias.join(' ') : option.alias}` : undefined, + summary: command.description, + remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined, }, - optional: true, - }); - } - - // add positional argument associated with the command - if (command.arg) { - commandType.addProperty({ - name: command.arg.name, - type: command.arg.variadic ? Type.arrayOf(Type.STRING) : Type.STRING, - docs: { - summary: `Positional argument for ${commandName}`, - }, - optional: true, }); + commandType = Type.fromName(scope, commandStruct.name); + + // add command level options + for (const [optionName, option] of commandOptions) { + commandStruct.addProperty({ + name: kebabToCamelCase(optionName), + type: convertType(option.type, option.count), + docs: { + // Notification Arns is a special property where undefined and [] mean different things + default: optionName === 'notification-arns' ? 'undefined' : normalizeDefault(option.default), + summary: option.desc, + deprecated: option.deprecated ? String(option.deprecated) : undefined, + remarks: option.alias ? `aliases: ${Array.isArray(option.alias) ? option.alias.join(' ') : option.alias}` : undefined, + }, + optional: true, + }); + } + + // add positional argument associated with the command + if (command.arg) { + commandStruct.addProperty({ + name: command.arg.name, + type: command.arg.variadic ? Type.arrayOf(Type.STRING) : Type.STRING, + docs: { + summary: `Positional argument for ${commandName}`, + }, + optional: true, + }); + } } userInputType.addProperty({ name: kebabToCamelCase(commandName), - type: Type.fromName(scope, commandType.name), + type: commandType, docs: { summary: command.description, remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined, diff --git a/packages/aws-cdk/lib/cli/user-input.ts b/packages/aws-cdk/lib/cli/user-input.ts index a51ae5e9..9acb5457 100644 --- a/packages/aws-cdk/lib/cli/user-input.ts +++ b/packages/aws-cdk/lib/cli/user-input.ts @@ -117,7 +117,7 @@ export interface UserInput { /** * Check your set-up for potential problems */ - readonly doctor?: DoctorOptions; + readonly doctor?: {}; } /** @@ -1325,11 +1325,3 @@ export interface DocsOptions { */ readonly browser?: string; } - -/** - * Check your set-up for potential problems - * - * @struct - */ -export interface DoctorOptions { -}