From 56ed0e57e33b343d88561c0ff7a1ffdf3d02eba6 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:37:02 -0500 Subject: [PATCH] chore(cli): turn cliArguments into camelCase (#32697) This just standardizes the style more similarly to the rest of aws-cdk ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk/lib/cli-arguments.ts | 106 +++++++++--------- packages/aws-cdk/test/cli-arguments.test.ts | 8 +- .../@aws-cdk/cli-args-gen/lib/cli-type-gen.ts | 15 +-- tools/@aws-cdk/cli-args-gen/lib/util.ts | 18 +++ .../cli-args-gen/test/cli-type-gen.test.ts | 4 +- 5 files changed, 81 insertions(+), 70 deletions(-) diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 48aca1dbde915..f9c517e2da3fd 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -180,7 +180,7 @@ export interface GlobalOptions { * * @default - false */ - readonly 'ignore-errors'?: boolean; + readonly ignoreErrors?: boolean; /** * Use JSON output instead of YAML when templates are printed to STDOUT @@ -222,7 +222,7 @@ export interface GlobalOptions { * * @default - undefined */ - readonly 'ca-bundle-path'?: string; + readonly caBundlePath?: string; /** * Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status @@ -236,28 +236,28 @@ export interface GlobalOptions { * * @default - undefined */ - readonly 'version-reporting'?: boolean; + readonly versionReporting?: boolean; /** * Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default) * * @default - undefined */ - readonly 'path-metadata'?: boolean; + readonly pathMetadata?: boolean; /** * Include "aws:asset:*" CloudFormation metadata for resources that uses assets (enabled by default) * * @default - undefined */ - readonly 'asset-metadata'?: boolean; + readonly assetMetadata?: boolean; /** * ARN of Role to use when invoking CloudFormation * * @default - undefined */ - readonly 'role-arn'?: string; + readonly roleArn?: string; /** * Copy assets to the output directory (use --no-staging to disable the copy of assets which allows local debugging via the SAM CLI to reference the original source files) @@ -285,7 +285,7 @@ export interface GlobalOptions { * * @default - false */ - readonly 'no-color'?: boolean; + readonly noColor?: boolean; /** * Force CI detection. If CI=true then logs will be sent to stdout instead of stderr @@ -326,7 +326,7 @@ export interface ListOptions { * * @default - false */ - readonly 'show-dependencies'?: boolean; + readonly showDependencies?: boolean; } /** @@ -376,14 +376,14 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'bootstrap-bucket-name'?: string; + readonly bootstrapBucketName?: string; /** * AWS KMS master key ID used for the SSE-KMS encryption * * @default - undefined */ - readonly 'bootstrap-kms-key-id'?: string; + readonly bootstrapKmsKeyId?: string; /** * Use the example permissions boundary. @@ -392,7 +392,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'example-permissions-boundary'?: boolean; + readonly examplePermissionsBoundary?: boolean; /** * Use the permissions boundary specified by name. @@ -401,14 +401,14 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'custom-permissions-boundary'?: string; + readonly customPermissionsBoundary?: string; /** * Create a Customer Master Key (CMK) for the bootstrap bucket (you will be charged but can customize permissions, modern bootstrapping only) * * @default - undefined */ - readonly 'bootstrap-customer-key'?: boolean; + readonly bootstrapCustomerKey?: boolean; /** * String which must be unique for each bootstrap stack. You must configure it on your CDK app if you change this from the default. @@ -422,7 +422,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'public-access-block-configuration'?: boolean; + readonly publicAccessBlockConfiguration?: boolean; /** * Tags to add for the stack (KEY=VALUE) @@ -452,14 +452,14 @@ export interface BootstrapOptions { * * @default - [] */ - readonly 'trust-for-lookup'?: Array; + readonly trustForLookup?: Array; /** * The Managed Policy ARNs that should be attached to the role performing deployments into this environment (may be repeated, modern bootstrapping only) * * @default - [] */ - readonly 'cloudformation-execution-policies'?: Array; + readonly cloudformationExecutionPolicies?: Array; /** * Always bootstrap even if it would downgrade template version @@ -475,21 +475,21 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'termination-protection'?: boolean; + readonly terminationProtection?: boolean; /** * Instead of actual bootstrapping, print the current CLI's bootstrapping template to stdout for customization * * @default - false */ - readonly 'show-template'?: boolean; + readonly showTemplate?: boolean; /** * The name of the CDK toolkit stack to create * * @default - undefined */ - readonly 'toolkit-stack-name'?: string; + readonly toolkitStackName?: string; /** * Use the template from the given file instead of the built-in one (use --show-template to obtain an example) @@ -503,7 +503,7 @@ export interface BootstrapOptions { * * @default - true */ - readonly 'previous-parameters'?: boolean; + readonly previousParameters?: boolean; } /** @@ -531,14 +531,14 @@ export interface GcOptions { * * @default - 0 */ - readonly 'rollback-buffer-days'?: number; + readonly rollbackBufferDays?: number; /** * Never delete assets younger than this (in days) * * @default - 1 */ - readonly 'created-buffer-days'?: number; + readonly createdBufferDays?: number; /** * Confirm via manual prompt before deletion @@ -552,7 +552,7 @@ export interface GcOptions { * * @default - undefined */ - readonly 'bootstrap-stack-name'?: string; + readonly bootstrapStackName?: string; } /** @@ -575,7 +575,7 @@ export interface DeployOptions { * * @default - [] */ - readonly 'build-exclude'?: Array; + readonly buildExclude?: Array; /** * Only deploy requested stacks, don't include dependencies @@ -591,14 +591,14 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'require-approval'?: string; + readonly requireApproval?: string; /** * ARNs of SNS topics that CloudFormation will notify with stack related events. These will be added to ARNs specified with the 'notificationArns' stack property. * * @default - undefined */ - readonly 'notification-arns'?: Array; + readonly notificationArns?: Array; /** * Tags to add to the stack (KEY=VALUE), overrides tags from Cloud Assembly (deprecated) @@ -622,7 +622,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'change-set-name'?: string; + readonly changeSetName?: string; /** * How to perform the deployment. Direct is a bit faster but lacks progress information @@ -656,21 +656,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'outputs-file'?: string; + readonly outputsFile?: string; /** * Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled) * * @default - true */ - readonly 'previous-parameters'?: boolean; + readonly previousParameters?: boolean; /** * The name of the existing CDK toolkit stack (only used for app using legacy synthesis) * * @default - undefined */ - readonly 'toolkit-stack-name'?: string; + readonly toolkitStackName?: string; /** * Display mode for stack activity events @@ -698,7 +698,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'hotswap-fallback'?: boolean; + readonly hotswapFallback?: boolean; /** * Continuously observe the project files, and deploy the given stack(s) automatically when changes are detected. Implies --hotswap by default @@ -726,21 +726,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'asset-parallelism'?: boolean; + readonly assetParallelism?: boolean; /** * Whether to build all assets before deploying the first stack (useful for failing Docker builds) * * @default - true */ - readonly 'asset-prebuild'?: boolean; + readonly assetPrebuild?: boolean; /** * Whether to deploy if the app contains no stacks * * @default - false */ - readonly 'ignore-no-stacks'?: boolean; + readonly ignoreNoStacks?: boolean; } /** @@ -761,7 +761,7 @@ export interface RollbackOptions { * * @default - undefined */ - readonly 'toolkit-stack-name'?: string; + readonly toolkitStackName?: string; /** * Orphan all resources for which the rollback operation fails. @@ -777,7 +777,7 @@ export interface RollbackOptions { * * @default - undefined */ - readonly 'validate-bootstrap-version'?: boolean; + readonly validateBootstrapVersion?: boolean; /** * Orphan the given resources, identified by their logical ID (can be specified multiple times) @@ -805,14 +805,14 @@ export interface ImportOptions { * * @default - undefined */ - readonly 'change-set-name'?: string; + readonly changeSetName?: string; /** * The name of the CDK toolkit stack to create * * @default - undefined */ - readonly 'toolkit-stack-name'?: string; + readonly toolkitStackName?: string; /** * Rollback stack to stable state on failure. Defaults to 'true', iterate more rapidly with --no-rollback or -R. Note: do **not** disable this flag for deployments with resource replacements, as that will always fail @@ -837,7 +837,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly 'record-resource-mapping'?: string; + readonly recordResourceMapping?: string; /** * If specified, CDK will use the given file to map physical resources to CDK resources for import, instead of interactively asking the user. Can be run from scripts @@ -846,7 +846,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly 'resource-mapping'?: string; + readonly resourceMapping?: string; } /** @@ -862,7 +862,7 @@ export interface WatchOptions { * * @default - [] */ - readonly 'build-exclude'?: Array; + readonly buildExclude?: Array; /** * Only deploy requested stacks, don't include dependencies @@ -878,7 +878,7 @@ export interface WatchOptions { * * @default - undefined */ - readonly 'change-set-name'?: string; + readonly changeSetName?: string; /** * Always deploy stack even if templates are identical @@ -894,7 +894,7 @@ export interface WatchOptions { * * @default - undefined */ - readonly 'toolkit-stack-name'?: string; + readonly toolkitStackName?: string; /** * Display mode for stack activity events @@ -922,7 +922,7 @@ export interface WatchOptions { * * @default - undefined */ - readonly 'hotswap-fallback'?: boolean; + readonly hotswapFallback?: boolean; /** * Show CloudWatch log events from all resources in the selected Stacks in the terminal. 'true' by default, use --no-logs to turn off @@ -991,7 +991,7 @@ export interface DiffOptions { * * @default - 3 */ - readonly 'context-lines'?: number; + readonly contextLines?: number; /** * The path to the CloudFormation template to compare with @@ -1012,7 +1012,7 @@ export interface DiffOptions { * * @default - false */ - readonly 'security-only'?: boolean; + readonly securityOnly?: boolean; /** * Fail with exit code 1 in case of diff @@ -1044,7 +1044,7 @@ export interface DiffOptions { * * @default - true */ - readonly 'change-set'?: boolean; + readonly changeSet?: boolean; } /** @@ -1106,7 +1106,7 @@ export interface InitOptions { * * @default - false */ - readonly 'generate-only'?: boolean; + readonly generateOnly?: boolean; } /** @@ -1122,7 +1122,7 @@ export interface MigrateOptions { * * @default - undefined */ - readonly 'stack-name'?: string; + readonly stackName?: string; /** * The language to be used for the new project @@ -1152,21 +1152,21 @@ export interface MigrateOptions { * * @default - undefined */ - readonly 'from-path'?: string; + readonly fromPath?: string; /** * Use this flag to retrieve the template for an existing CloudFormation stack * * @default - undefined */ - readonly 'from-stack'?: boolean; + readonly fromStack?: boolean; /** * The output path for the migrated CDK app * * @default - undefined */ - readonly 'output-path'?: string; + readonly outputPath?: string; /** * Determines if a new scan should be created, or the last successful existing scan should be used @@ -1174,7 +1174,7 @@ export interface MigrateOptions { * * @default - undefined */ - readonly 'from-scan'?: string; + readonly fromScan?: string; /** * Filters the resource scan based on the provided criteria in the following format: "key1=value1,key2=value2" diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index c1e4bcc56c1fe..24ad03c46aaa6 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -7,10 +7,10 @@ test('cli arguments can be used as a type', async () => { const argv: CliArguments = { _: [Command.DEPLOY], globalOptions: { - 'lookups': true, - 'ignore-errors': false, - 'json': false, - 'verbose': false, + lookups: true, + ignoreErrors: false, + json: false, + verbose: false, }, }; diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts index a250415035cd7..84ee0bdca21bd 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts @@ -1,7 +1,7 @@ import { Module, SelectiveModuleImport, StructType, Type, TypeScriptRenderer } from '@cdklabs/typewriter'; import { EsLintRules } from '@cdklabs/typewriter/lib/eslint-rules'; import * as prettier from 'prettier'; -import { generateDefault } from './util'; +import { generateDefault, kebabToCamelCase, kebabToPascal } from './util'; import { CliConfig } from './yargs-types'; export async function renderCliType(config: CliConfig): Promise { @@ -42,7 +42,7 @@ export async function renderCliType(config: CliConfig): Promise { }); for (const [optionName, option] of Object.entries(config.globalOptions)) { globalOptionType.addProperty({ - name: optionName, + name: kebabToCamelCase(optionName), type: convertType(option.type), docs: { default: normalizeDefault(option.default, option.type), @@ -74,7 +74,7 @@ export async function renderCliType(config: CliConfig): Promise { for (const [optionName, option] of Object.entries(command.options ?? {})) { commandType.addProperty({ - name: optionName, + name: kebabToCamelCase(optionName), type: convertType(option.type), docs: { // Notification Arns is a special property where undefined and [] mean different things @@ -88,7 +88,7 @@ export async function renderCliType(config: CliConfig): Promise { } cliArgType.addProperty({ - name: commandName, + name: kebabToCamelCase(commandName), type: Type.fromName(scope, commandType.name), docs: { summary: command.description, @@ -124,13 +124,6 @@ function convertType(type: 'string' | 'array' | 'number' | 'boolean' | 'count'): } } -function kebabToPascal(str: string): string { - return str - .split('-') - .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) - .join(''); -} - function normalizeDefault(defaultValue: any, type: string): string { switch (typeof defaultValue) { case 'boolean': diff --git a/tools/@aws-cdk/cli-args-gen/lib/util.ts b/tools/@aws-cdk/cli-args-gen/lib/util.ts index 047c2498283c6..7a0d99a0c3879 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/util.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/util.ts @@ -1,3 +1,21 @@ export function generateDefault(type: string) { return type === 'array' ? [] : undefined; } + +export function kebabToCamelCase(str: string): string { + return str + .split('-') + .map((word, index) => + index === 0 + ? word.toLowerCase() + : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(), + ) + .join(''); +} + +export function kebabToPascal(str: string): string { + return str + .split('-') + .map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) + .join(''); +} diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts index 621b8e060b088..a3d119fc5fd89 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts @@ -188,14 +188,14 @@ describe('render', () => { * * @default - undefined */ - readonly 'notification-arns'?: Array; + readonly notificationArns?: Array; /** * Other array * * @default - [] */ - readonly 'other-array'?: Array; + readonly otherArray?: Array; } " `);