Skip to content

Commit 7517ecc

Browse files
authored
chore(cli): don't emit empty user input interfaces (#93)
Fixes the generated empty interface not complying with our eslint rule to have newlines between control curly braces. ```ts // not-allowed, but previously generated interface DocsOptions {} ``` Instead we just avoid the problem by not generating empty interfaces. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 539868d commit 7517ecc

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

packages/@aws-cdk/user-input-gen/lib/user-input-gen.ts

+40-33
Original file line numberDiff line numberDiff line change
@@ -65,46 +65,53 @@ export async function renderUserInputType(config: CliConfig): Promise<string> {
6565

6666
// add command-specific options
6767
for (const [commandName, command] of Object.entries(config.commands)) {
68-
const commandType = new StructType(scope, {
69-
export: true,
70-
name: `${kebabToPascal(commandName)}Options`,
71-
docs: {
72-
summary: command.description,
73-
remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined,
74-
},
75-
});
76-
77-
// add command level options
78-
for (const [optionName, option] of Object.entries(command.options ?? {})) {
79-
commandType.addProperty({
80-
name: kebabToCamelCase(optionName),
81-
type: convertType(option.type, option.count),
68+
let commandType: Type = Type.anonymousInterface([]);
69+
const commandOptions = Object.entries(command.options ?? {});
70+
71+
// if we have something to add to an interface
72+
if (command.arg || commandOptions.length) {
73+
const commandStruct = new StructType(scope, {
74+
export: true,
75+
name: `${kebabToPascal(commandName)}Options`,
8276
docs: {
83-
// Notification Arns is a special property where undefined and [] mean different things
84-
default: optionName === 'notification-arns' ? 'undefined' : normalizeDefault(option.default),
85-
summary: option.desc,
86-
deprecated: option.deprecated ? String(option.deprecated) : undefined,
87-
remarks: option.alias ? `aliases: ${Array.isArray(option.alias) ? option.alias.join(' ') : option.alias}` : undefined,
77+
summary: command.description,
78+
remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined,
8879
},
89-
optional: true,
90-
});
91-
}
92-
93-
// add positional argument associated with the command
94-
if (command.arg) {
95-
commandType.addProperty({
96-
name: command.arg.name,
97-
type: command.arg.variadic ? Type.arrayOf(Type.STRING) : Type.STRING,
98-
docs: {
99-
summary: `Positional argument for ${commandName}`,
100-
},
101-
optional: true,
10280
});
81+
commandType = Type.fromName(scope, commandStruct.name);
82+
83+
// add command level options
84+
for (const [optionName, option] of commandOptions) {
85+
commandStruct.addProperty({
86+
name: kebabToCamelCase(optionName),
87+
type: convertType(option.type, option.count),
88+
docs: {
89+
// Notification Arns is a special property where undefined and [] mean different things
90+
default: optionName === 'notification-arns' ? 'undefined' : normalizeDefault(option.default),
91+
summary: option.desc,
92+
deprecated: option.deprecated ? String(option.deprecated) : undefined,
93+
remarks: option.alias ? `aliases: ${Array.isArray(option.alias) ? option.alias.join(' ') : option.alias}` : undefined,
94+
},
95+
optional: true,
96+
});
97+
}
98+
99+
// add positional argument associated with the command
100+
if (command.arg) {
101+
commandStruct.addProperty({
102+
name: command.arg.name,
103+
type: command.arg.variadic ? Type.arrayOf(Type.STRING) : Type.STRING,
104+
docs: {
105+
summary: `Positional argument for ${commandName}`,
106+
},
107+
optional: true,
108+
});
109+
}
103110
}
104111

105112
userInputType.addProperty({
106113
name: kebabToCamelCase(commandName),
107-
type: Type.fromName(scope, commandType.name),
114+
type: commandType,
108115
docs: {
109116
summary: command.description,
110117
remarks: command.aliases ? `aliases: ${command.aliases.join(' ')}` : undefined,

packages/aws-cdk/lib/cli/user-input.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export interface UserInput {
117117
/**
118118
* Check your set-up for potential problems
119119
*/
120-
readonly doctor?: DoctorOptions;
120+
readonly doctor?: {};
121121
}
122122

123123
/**
@@ -1325,11 +1325,3 @@ export interface DocsOptions {
13251325
*/
13261326
readonly browser?: string;
13271327
}
1328-
1329-
/**
1330-
* Check your set-up for potential problems
1331-
*
1332-
* @struct
1333-
*/
1334-
export interface DoctorOptions {
1335-
}

0 commit comments

Comments
 (0)