Skip to content

Commit

Permalink
chore(cli): cli arguments with "count: true" are generated as number …
Browse files Browse the repository at this point in the history
…types (#32758)

Our cli config has the following for `verbose`: `type: boolean, count: true`. That should be a `number` type, but it currently is a `boolean` type. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Jan 7, 2025
1 parent db345c5 commit ac3ffa5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/cli-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export interface GlobalOptions {
*
* @default - false
*/
readonly verbose?: boolean;
readonly verbose?: number;

/**
* Debug the CDK app. Log additional information during synthesis, such as creation stack traces of tokens (sets CDK_DEBUG, will slow down synthesis)
Expand Down
8 changes: 4 additions & 4 deletions tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function renderCliArgsType(config: CliConfig): Promise<string> {
for (const [optionName, option] of Object.entries(config.globalOptions)) {
globalOptionType.addProperty({
name: kebabToCamelCase(optionName),
type: convertType(option.type),
type: convertType(option.type, option.count),
docs: {
default: normalizeDefault(option.default, option.type),
summary: option.desc,
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function renderCliArgsType(config: CliConfig): Promise<string> {
for (const [optionName, option] of Object.entries(command.options ?? {})) {
commandType.addProperty({
name: kebabToCamelCase(optionName),
type: convertType(option.type),
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, option.type),
Expand Down Expand Up @@ -124,10 +124,10 @@ export async function renderCliArgsType(config: CliConfig): Promise<string> {
});
}

function convertType(type: 'string' | 'array' | 'number' | 'boolean' | 'count'): Type {
function convertType(type: 'string' | 'array' | 'number' | 'boolean' | 'count', count?: boolean): Type {
switch (type) {
case 'boolean':
return Type.BOOLEAN;
return count ? Type.NUMBER : Type.BOOLEAN;
case 'string':
return Type.STRING;
case 'number':
Expand Down
12 changes: 12 additions & 0 deletions tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ describe('render', () => {
desc: 'Enable debug logging',
default: false,
},
verbose: {
type: 'boolean',
count: true,
desc: 'Increase logging verbosity',
},
context: {
default: [],
type: 'array',
Expand Down Expand Up @@ -88,6 +93,13 @@ describe('render', () => {
*/
readonly debug?: boolean;
/**
* Increase logging verbosity
*
* @default - undefined
*/
readonly verbose?: number;
/**
* context values
*
Expand Down

0 comments on commit ac3ffa5

Please sign in to comment.