diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts index 3fc1b9a2bc541..dd11a124f9a3e 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -38,6 +38,7 @@ export function convertToCliArgs(args: any): CliArguments { let commandOptions; switch (args._[0] as Command) { case 'list': + case 'ls': commandOptions = { long: args.long, showDependencies: args.showDependencies, @@ -46,6 +47,7 @@ export function convertToCliArgs(args: any): CliArguments { break; case 'synthesize': + case 'synth': commandOptions = { exclusively: args.exclusively, validation: args.validation, @@ -193,6 +195,7 @@ export function convertToCliArgs(args: any): CliArguments { break; case 'acknowledge': + case 'ack': commandOptions = { ID: args.ID, }; @@ -237,6 +240,7 @@ export function convertToCliArgs(args: any): CliArguments { break; case 'docs': + case 'doc': commandOptions = { browser: args.browser, }; diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index c29ae2045c0ac..9c6e680e6c8d8 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -36,10 +36,12 @@ export enum Command { ROLLBACK = 'rollback', IMPORT = 'import', ACKNOWLEDGE = 'acknowledge', + ACK = 'ack', NOTICES = 'notices', MIGRATE = 'migrate', CONTEXT = 'context', DOCS = 'docs', + DOC = 'doc', DOCTOR = 'doctor', } diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts index cb7e6a6dd22d4..9cb34988da8ea 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts @@ -64,7 +64,9 @@ function buildCommandSwitch(config: CliConfig): string { const commandSwitchExprs = ['let commandOptions;', 'switch (args._[0] as Command) {']; for (const commandName of Object.keys(config.commands)) { commandSwitchExprs.push( - `case '${commandName}':`, + // All aliases of the command should map to the same switch branch + // This ensures that we store options of the command regardless of what alias is specified + ...buildAliases(commandName, config.commands[commandName].aliases), 'commandOptions = {', ...buildCommandOptions(config.commands[commandName]), ...(config.commands[commandName].arg ? [buildPositionalArguments(config.commands[commandName].arg)] : []), @@ -76,6 +78,11 @@ function buildCommandSwitch(config: CliConfig): string { return commandSwitchExprs.join('\n'); } +function buildAliases(commandName: string, aliases: string[] = []): string[] { + const cases = [commandName, ...aliases]; + return cases.map((c) => `case '${c}':`); +} + function buildCommandOptions(options: CliAction): string[] { const commandOptions: string[] = []; for (const optionName of Object.keys(options.options ?? {})) { diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts index 24b92c7fe291e..0660f7df34468 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts @@ -31,6 +31,7 @@ describe('render', () => { variadic: true, }, description: 'Deploy a stack', + aliases: ['d'], options: { all: { type: 'boolean', @@ -62,6 +63,7 @@ describe('render', () => { let commandOptions; switch (args._[0] as Command) { case 'deploy': + case 'd': commandOptions = { all: args.all, STACKS: args.STACKS,