From de4838fdfc6fd9202af00b5e41b7f3fc158c0965 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Mon, 30 Dec 2024 11:49:42 -0500 Subject: [PATCH 1/9] chore(cli): update Command enum --- packages/aws-cdk/lib/settings.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/aws-cdk/lib/settings.ts b/packages/aws-cdk/lib/settings.ts index 58755af786643..c29ae2045c0ac 100644 --- a/packages/aws-cdk/lib/settings.ts +++ b/packages/aws-cdk/lib/settings.ts @@ -32,6 +32,15 @@ export enum Command { INIT = 'init', VERSION = 'version', WATCH = 'watch', + GC = 'gc', + ROLLBACK = 'rollback', + IMPORT = 'import', + ACKNOWLEDGE = 'acknowledge', + NOTICES = 'notices', + MIGRATE = 'migrate', + CONTEXT = 'context', + DOCS = 'docs', + DOCTOR = 'doctor', } const BUNDLING_COMMANDS = [ From 919c6d9e0b349a58bcc2ec18b6df639daf0159f0 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 31 Dec 2024 10:13:51 -0500 Subject: [PATCH 2/9] chore(cli): function to turn yargs output to cliArguments --- packages/aws-cdk/lib/cli-arguments.ts | 367 ++++++++++++++---- packages/aws-cdk/test/cli-arguments.test.ts | 113 +++++- .../@aws-cdk/cli-args-gen/lib/cli-type-gen.ts | 102 ++++- tools/@aws-cdk/cli-args-gen/lib/util.ts | 14 + tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts | 12 +- .../@aws-cdk/cli-args-gen/lib/yargs-types.ts | 2 +- 6 files changed, 516 insertions(+), 94 deletions(-) diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 48aca1dbde915..052c20cd3011d 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -131,49 +131,49 @@ export interface GlobalOptions { * * @default - undefined */ - readonly app?: string; + readonly 'app'?: string; /** * Command-line for a pre-synth build * * @default - undefined */ - readonly build?: string; + readonly 'build'?: string; /** * Add contextual string parameter (KEY=VALUE) * * @default - [] */ - readonly context?: Array; + readonly 'context'?: Array; /** * Name or path of a node package that extend the CDK features. Can be specified multiple times * * @default - [] */ - readonly plugin?: Array; + readonly 'plugin'?: Array; /** * Print trace for stack warnings * * @default - undefined */ - readonly trace?: boolean; + readonly 'trace'?: boolean; /** * Do not construct stacks with warnings * * @default - undefined */ - readonly strict?: boolean; + readonly 'strict'?: boolean; /** * Perform context lookups (synthesis fails if this is disabled and context lookups need to be performed) * * @default - true */ - readonly lookups?: boolean; + readonly 'lookups'?: boolean; /** * Ignores synthesis errors, which will likely produce an invalid output @@ -187,35 +187,35 @@ export interface GlobalOptions { * * @default - false */ - readonly json?: boolean; + readonly 'json'?: boolean; /** * Show debug logs (specify multiple times to increase verbosity) * * @default - false */ - readonly verbose?: boolean; + readonly 'verbose'?: boolean; /** * Debug the CDK app. Log additional information during synthesis, such as creation stack traces of tokens (sets CDK_DEBUG, will slow down synthesis) * * @default - false */ - readonly debug?: boolean; + readonly 'debug'?: boolean; /** * Use the indicated AWS profile as the default environment * * @default - undefined */ - readonly profile?: string; + readonly 'profile'?: string; /** * Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified * * @default - undefined */ - readonly proxy?: string; + readonly 'proxy'?: string; /** * Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified @@ -229,7 +229,7 @@ export interface GlobalOptions { * * @default - undefined */ - readonly ec2creds?: boolean; + readonly 'ec2creds'?: boolean; /** * Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default) @@ -264,21 +264,21 @@ export interface GlobalOptions { * * @default - true */ - readonly staging?: boolean; + readonly 'staging'?: boolean; /** * Emits the synthesized cloud assembly into a directory (default: cdk.out) * * @default - undefined */ - readonly output?: string; + readonly 'output'?: string; /** * Show relevant notices * * @default - undefined */ - readonly notices?: boolean; + readonly 'notices'?: boolean; /** * Removes colors and other style from console output @@ -292,14 +292,14 @@ export interface GlobalOptions { * * @default - undefined */ - readonly ci?: boolean; + readonly 'ci'?: boolean; /** * Opt in to unstable features. The flag indicates that the scope and API of a feature might still change. Otherwise the feature is generally production ready and fully supported. Can be specified multiple times. * * @default - [] */ - readonly unstable?: Array; + readonly 'unstable'?: Array; } /** @@ -317,7 +317,7 @@ export interface ListOptions { * * @default - false */ - readonly long?: boolean; + readonly 'long'?: boolean; /** * Display stack dependency information for each stack @@ -415,7 +415,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly qualifier?: string; + readonly 'qualifier'?: string; /** * Block public access configuration on CDK toolkit bucket (enabled by default) @@ -431,21 +431,21 @@ export interface BootstrapOptions { * * @default - [] */ - readonly tags?: Array; + readonly 'tags'?: Array; /** * Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet) * * @default - true */ - readonly execute?: boolean; + readonly 'execute'?: boolean; /** * The AWS account IDs that should be trusted to perform deployments into this environment (may be repeated, modern bootstrapping only) * * @default - [] */ - readonly trust?: Array; + readonly 'trust'?: Array; /** * The AWS account IDs that should be trusted to look up values in this environment (may be repeated, modern bootstrapping only) @@ -468,7 +468,7 @@ export interface BootstrapOptions { * * @default - false */ - readonly force?: boolean; + readonly 'force'?: boolean; /** * Toggle CloudFormation termination protection on the bootstrap stacks @@ -496,7 +496,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly template?: string; + readonly 'template'?: string; /** * Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled) @@ -517,14 +517,14 @@ export interface GcOptions { * * @default - "full" */ - readonly action?: string; + readonly 'action'?: string; /** * Specify either ecr, s3, or all * * @default - "all" */ - readonly type?: string; + readonly 'type'?: string; /** * Delete assets that have been marked as isolated for this many days @@ -545,7 +545,7 @@ export interface GcOptions { * * @default - true */ - readonly confirm?: boolean; + readonly 'confirm'?: boolean; /** * The name of the CDK toolkit stack, if different from the default "CDKToolkit" @@ -566,7 +566,7 @@ export interface DeployOptions { * * @default - false */ - readonly all?: boolean; + readonly 'all'?: boolean; /** * Do not rebuild asset with the given ID. Can be specified multiple times @@ -584,7 +584,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly exclusively?: boolean; + readonly 'exclusively'?: boolean; /** * What security-sensitive changes need manual approval @@ -607,7 +607,7 @@ export interface DeployOptions { * * @default - [] */ - readonly tags?: Array; + readonly 'tags'?: Array; /** * Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet) (deprecated) @@ -615,7 +615,7 @@ export interface DeployOptions { * @deprecated true * @default - undefined */ - readonly execute?: boolean; + readonly 'execute'?: boolean; /** * Name of the CloudFormation change set to create (only if method is not direct) @@ -631,7 +631,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly method?: string; + readonly 'method'?: string; /** * Always deploy stack even if templates are identical @@ -640,14 +640,14 @@ export interface DeployOptions { * * @default - false */ - readonly force?: boolean; + readonly 'force'?: boolean; /** * Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE) * * @default - {} */ - readonly parameters?: Array; + readonly 'parameters'?: Array; /** * Path to file where stack outputs will be written as JSON @@ -677,21 +677,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly progress?: string; + readonly 'progress'?: 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 * * @default - undefined */ - readonly rollback?: boolean; + readonly 'rollback'?: boolean; /** * Attempts to perform a 'hotswap' deployment, but does not fall back to a full deployment if that is not possible. Instead, changes to any non-hotswappable properties are ignored.Do not use this in production environments * * @default - undefined */ - readonly hotswap?: boolean; + readonly 'hotswap'?: boolean; /** * Attempts to perform a 'hotswap' deployment, which skips CloudFormation and updates the resources directly, and falls back to a full deployment if that is not possible. Do not use this in production environments @@ -705,21 +705,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly watch?: boolean; + readonly 'watch'?: boolean; /** * Show CloudWatch log events from all resources in the selected Stacks in the terminal. 'true' by default, use --no-logs to turn off. Only in effect if specified alongside the '--watch' option * * @default - true */ - readonly logs?: boolean; + readonly 'logs'?: boolean; /** * Maximum number of simultaneous deployments (dependency permitting) to execute. * * @default - 1 */ - readonly concurrency?: number; + readonly 'concurrency'?: number; /** * Whether to build/publish assets in parallel @@ -754,7 +754,7 @@ export interface RollbackOptions { * * @default - false */ - readonly all?: boolean; + readonly 'all'?: boolean; /** * The name of the CDK toolkit stack the environment is bootstrapped with @@ -770,7 +770,7 @@ export interface RollbackOptions { * * @default - undefined */ - readonly force?: boolean; + readonly 'force'?: boolean; /** * Whether to validate the bootstrap stack version. Defaults to 'true', disable with --no-validate-bootstrap-version. @@ -784,7 +784,7 @@ export interface RollbackOptions { * * @default - [] */ - readonly orphan?: Array; + readonly 'orphan'?: Array; } /** @@ -798,7 +798,7 @@ export interface ImportOptions { * * @default - true */ - readonly execute?: boolean; + readonly 'execute'?: boolean; /** * Name of the CloudFormation change set to create @@ -819,7 +819,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly rollback?: boolean; + readonly 'rollback'?: boolean; /** * Do not abort if the template diff includes updates or deletes. This is probably safe but we're not sure, let us know how it goes. @@ -828,7 +828,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly force?: boolean; + readonly 'force'?: boolean; /** * If specified, CDK will generate a mapping of existing physical resources to CDK resources to be imported as. The mapping will be written in the given file path. No actual import operation will be performed @@ -871,7 +871,7 @@ export interface WatchOptions { * * @default - undefined */ - readonly exclusively?: boolean; + readonly 'exclusively'?: boolean; /** * Name of the CloudFormation change set to create @@ -887,7 +887,7 @@ export interface WatchOptions { * * @default - false */ - readonly force?: boolean; + readonly 'force'?: boolean; /** * The name of the existing CDK toolkit stack (only used for app using legacy synthesis) @@ -901,21 +901,21 @@ export interface WatchOptions { * * @default - undefined */ - readonly progress?: string; + readonly 'progress'?: 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 * * @default - undefined */ - readonly rollback?: boolean; + readonly 'rollback'?: boolean; /** * Attempts to perform a 'hotswap' deployment, but does not fall back to a full deployment if that is not possible. Instead, changes to any non-hotswappable properties are ignored.'true' by default, use --no-hotswap to turn off * * @default - undefined */ - readonly hotswap?: boolean; + readonly 'hotswap'?: boolean; /** * Attempts to perform a 'hotswap' deployment, which skips CloudFormation and updates the resources directly, and falls back to a full deployment if that is not possible. @@ -929,14 +929,14 @@ export interface WatchOptions { * * @default - true */ - readonly logs?: boolean; + readonly 'logs'?: boolean; /** * Maximum number of simultaneous deployments (dependency permitting) to execute. * * @default - 1 */ - readonly concurrency?: number; + readonly 'concurrency'?: number; } /** @@ -984,7 +984,7 @@ export interface DiffOptions { * * @default - undefined */ - readonly exclusively?: boolean; + readonly 'exclusively'?: boolean; /** * Number of context lines to include in arbitrary JSON diff rendering @@ -998,14 +998,14 @@ export interface DiffOptions { * * @default - undefined */ - readonly template?: string; + readonly 'template'?: string; /** * Do not filter out AWS::CDK::Metadata resources, mangled non-ASCII characters, or the CheckBootstrapVersionRule * * @default - false */ - readonly strict?: boolean; + readonly 'strict'?: boolean; /** * Only diff for broadened security changes @@ -1019,14 +1019,14 @@ export interface DiffOptions { * * @default - undefined */ - readonly fail?: boolean; + readonly 'fail'?: boolean; /** * Whether to compare against the template with Transforms already processed * * @default - false */ - readonly processed?: boolean; + readonly 'processed'?: boolean; /** * Do not print stack name and default message when there is no diff to stdout @@ -1035,7 +1035,7 @@ export interface DiffOptions { * * @default - false */ - readonly quiet?: boolean; + readonly 'quiet'?: boolean; /** * Whether to create a changeset to analyze resource replacements. In this mode, diff will use the deploy role instead of the lookup role. @@ -1092,14 +1092,14 @@ export interface InitOptions { * * @default - undefined */ - readonly language?: string; + readonly 'language'?: string; /** * List the available templates * * @default - undefined */ - readonly list?: boolean; + readonly 'list'?: boolean; /** * If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project @@ -1131,21 +1131,21 @@ export interface MigrateOptions { * * @default - "typescript" */ - readonly language?: string; + readonly 'language'?: string; /** * The account to retrieve the CloudFormation stack template from * * @default - undefined */ - readonly account?: string; + readonly 'account'?: string; /** * The region to retrieve the CloudFormation stack template from * * @default - undefined */ - readonly region?: string; + readonly 'region'?: string; /** * The path to the CloudFormation template to migrate. Use this for locally stored templates @@ -1187,14 +1187,14 @@ export interface MigrateOptions { * * @default - [] */ - readonly filter?: Array; + readonly 'filter'?: Array; /** * Use this flag to zip the generated CDK app * * @default - undefined */ - readonly compress?: boolean; + readonly 'compress'?: boolean; } /** @@ -1253,3 +1253,236 @@ export interface DocsOptions { * @struct */ export interface DoctorOptions {} + +// @ts-ignore TS6133 +export function createCliArguments(args: any): CliArguments { + const globalOptions: GlobalOptions = { + 'app': args.app, + 'build': args.build, + 'context': args.context, + 'plugin': args.plugin, + 'trace': args.trace, + 'strict': args.strict, + 'lookups': args.lookups, + 'ignore-errors': args.ignoreErrors, + 'json': args.json, + 'verbose': args.verbose, + 'debug': args.debug, + 'profile': args.profile, + 'proxy': args.proxy, + 'ca-bundle-path': args.caBundlePath, + 'ec2creds': args.ec2creds, + 'version-reporting': args.versionReporting, + 'path-metadata': args.pathMetadata, + 'asset-metadata': args.assetMetadata, + 'role-arn': args.roleArn, + 'staging': args.staging, + 'output': args.output, + 'notices': args.notices, + 'no-color': args.noColor, + 'ci': args.ci, + 'unstable': args.unstable, + }; + let commandOptions; + switch (args._[0] as Command) { + case 'list': + commandOptions = { + 'long': args.long, + 'show-dependencies': args.showDependencies, + }; + break; + + case 'synthesize': + commandOptions = { + exclusively: args.exclusively, + validation: args.validation, + quiet: args.quiet, + }; + break; + + case 'bootstrap': + commandOptions = { + 'bootstrap-bucket-name': args.bootstrapBucketName, + 'bootstrap-kms-key-id': args.bootstrapKmsKeyId, + 'example-permissions-boundary': args.examplePermissionsBoundary, + 'custom-permissions-boundary': args.customPermissionsBoundary, + 'bootstrap-customer-key': args.bootstrapCustomerKey, + 'qualifier': args.qualifier, + 'public-access-block-configuration': args.publicAccessBlockConfiguration, + 'tags': args.tags, + 'execute': args.execute, + 'trust': args.trust, + 'trust-for-lookup': args.trustForLookup, + 'cloudformation-execution-policies': args.cloudformationExecutionPolicies, + 'force': args.force, + 'termination-protection': args.terminationProtection, + 'show-template': args.showTemplate, + 'toolkit-stack-name': args.toolkitStackName, + 'template': args.template, + 'previous-parameters': args.previousParameters, + }; + break; + + case 'gc': + commandOptions = { + 'action': args.action, + 'type': args.type, + 'rollback-buffer-days': args.rollbackBufferDays, + 'created-buffer-days': args.createdBufferDays, + 'confirm': args.confirm, + 'bootstrap-stack-name': args.bootstrapStackName, + }; + break; + + case 'deploy': + commandOptions = { + 'all': args.all, + 'build-exclude': args.buildExclude, + 'exclusively': args.exclusively, + 'require-approval': args.requireApproval, + 'notification-arns': args.notificationArns, + 'tags': args.tags, + 'execute': args.execute, + 'change-set-name': args.changeSetName, + 'method': args.method, + 'force': args.force, + 'parameters': args.parameters, + 'outputs-file': args.outputsFile, + 'previous-parameters': args.previousParameters, + 'toolkit-stack-name': args.toolkitStackName, + 'progress': args.progress, + 'rollback': args.rollback, + 'hotswap': args.hotswap, + 'hotswap-fallback': args.hotswapFallback, + 'watch': args.watch, + 'logs': args.logs, + 'concurrency': args.concurrency, + 'asset-parallelism': args.assetParallelism, + 'asset-prebuild': args.assetPrebuild, + 'ignore-no-stacks': args.ignoreNoStacks, + }; + break; + + case 'rollback': + commandOptions = { + 'all': args.all, + 'toolkit-stack-name': args.toolkitStackName, + 'force': args.force, + 'validate-bootstrap-version': args.validateBootstrapVersion, + 'orphan': args.orphan, + }; + break; + + case 'import': + commandOptions = { + 'execute': args.execute, + 'change-set-name': args.changeSetName, + 'toolkit-stack-name': args.toolkitStackName, + 'rollback': args.rollback, + 'force': args.force, + 'record-resource-mapping': args.recordResourceMapping, + 'resource-mapping': args.resourceMapping, + }; + break; + + case 'watch': + commandOptions = { + 'build-exclude': args.buildExclude, + 'exclusively': args.exclusively, + 'change-set-name': args.changeSetName, + 'force': args.force, + 'toolkit-stack-name': args.toolkitStackName, + 'progress': args.progress, + 'rollback': args.rollback, + 'hotswap': args.hotswap, + 'hotswap-fallback': args.hotswapFallback, + 'logs': args.logs, + 'concurrency': args.concurrency, + }; + break; + + case 'destroy': + commandOptions = { + all: args.all, + exclusively: args.exclusively, + force: args.force, + }; + break; + + case 'diff': + commandOptions = { + 'exclusively': args.exclusively, + 'context-lines': args.contextLines, + 'template': args.template, + 'strict': args.strict, + 'security-only': args.securityOnly, + 'fail': args.fail, + 'processed': args.processed, + 'quiet': args.quiet, + 'change-set': args.changeSet, + }; + break; + + case 'metadata': + commandOptions = {}; + break; + + case 'acknowledge': + commandOptions = {}; + break; + + case 'notices': + commandOptions = { + unacknowledged: args.unacknowledged, + }; + break; + + case 'init': + commandOptions = { + 'language': args.language, + 'list': args.list, + 'generate-only': args.generateOnly, + }; + break; + + case 'migrate': + commandOptions = { + 'stack-name': args.stackName, + 'language': args.language, + 'account': args.account, + 'region': args.region, + 'from-path': args.fromPath, + 'from-stack': args.fromStack, + 'output-path': args.outputPath, + 'from-scan': args.fromScan, + 'filter': args.filter, + 'compress': args.compress, + }; + break; + + case 'context': + commandOptions = { + reset: args.reset, + force: args.force, + clear: args.clear, + }; + break; + + case 'docs': + commandOptions = { + browser: args.browser, + }; + break; + + case 'doctor': + commandOptions = {}; + break; + } + const cliArguments: CliArguments = { + _: args._, + globalOptions, + [args._[0]]: commandOptions, + }; + + return cliArguments; +} diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index c1e4bcc56c1fe..bf89717ac816a 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -1,19 +1,106 @@ -import { CliArguments } from '../lib/cli-arguments'; -import { Command } from '../lib/settings'; +import { createCliArguments } from '../lib/cli-arguments'; -// CliArguments is not being used right now, so the testing suite is rather redundant. -// This file is meant to be populated when CliArguments is used. -test('cli arguments can be used as a type', async () => { - const argv: CliArguments = { - _: [Command.DEPLOY], +test('yargs object can be converted to cli arguments', async () => { + // This input represents what would come out of yargs, i.e. + // await parseCommandLineArguments(args); + const input = { + '_': ['deploy'], + 'notification-arns': ['[]'], + 'notificationArns': ['[]'], + 'v': 1, + 'verbose': 1, + 'lookups': true, + 'ignore-errors': false, + 'ignoreErrors': false, + 'json': false, + 'j': false, + 'debug': false, + 'ec2creds': undefined, + 'i': undefined, + 'version-reporting': undefined, + 'versionReporting': undefined, + 'path-metadata': undefined, + 'pathMetadata': undefined, + 'asset-metadata': undefined, + 'assetMetadata': undefined, + 'role-arn': undefined, + 'r': undefined, + 'roleArn': undefined, + 'staging': true, + 'no-color': false, + 'noColor': false, + 'ci': false, + 'unstable': [], + 'all': false, + 'build-exclude': [], + 'E': [], + 'buildExclude': [], + 'force': false, + 'f': false, + 'parameters': [{}], + 'previous-parameters': true, + 'previousParameters': true, + 'logs': true, + 'concurrency': 1, + 'asset-prebuild': true, + 'assetPrebuild': true, + 'ignore-no-stacks': false, + 'ignoreNoStacks': false, + }; + + const result = createCliArguments(input); + + expect(result).toEqual({ + _: ['deploy'], globalOptions: { - 'lookups': true, + 'app': undefined, + 'asset-metadata': undefined, + 'build': undefined, + 'ca-bundle-path': undefined, + 'context': undefined, 'ignore-errors': false, + 'no-color': false, + 'path-metadata': undefined, + 'proxy': undefined, + 'role-arn': undefined, + 'staging': true, + 'strict': undefined, + 'verbose': 1, + 'version-reporting': undefined, + 'ci': false, + 'debug': false, + 'ec2creds': undefined, 'json': false, - 'verbose': false, + 'lookups': true, + 'unstable': [], + 'notices': undefined, + 'output': undefined, }, - }; - - expect(argv._[0]).toBe('deploy'); - expect(argv.globalOptions?.lookups).toBeTruthy(); + deploy: { + 'all': false, + 'asset-parallelism': undefined, + 'asset-prebuild': true, + 'build-exclude': [], + 'change-set-name': undefined, + 'concurrency': 1, + 'execute': undefined, + 'exclusively': undefined, + 'force': false, + 'hotswap': undefined, + 'hotswap-fallback': undefined, + 'ignore-no-stacks': false, + 'logs': true, + 'method': undefined, + 'notification-arns': ['[]'], + 'outputs-file': undefined, + 'parameters': [{}], + 'previous-parameters': true, + 'progress': undefined, + 'require-approval': undefined, + 'rollback': undefined, + 'tags': undefined, + 'toolkit-stack-name': undefined, + 'watch': undefined, + }, + }); }); 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..7671b968f6d76 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,8 +1,8 @@ -import { Module, SelectiveModuleImport, StructType, Type, TypeScriptRenderer } from '@cdklabs/typewriter'; +import { code, FreeFunction, 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 { CliConfig } from './yargs-types'; +import { CliAction, CliConfig } from './yargs-types'; export async function renderCliType(config: CliConfig): Promise { const scope = new Module('aws-cdk'); @@ -52,6 +52,7 @@ export async function renderCliType(config: CliConfig): Promise { optional: true, }); } + cliArgType.addProperty({ name: 'globalOptions', type: Type.fromName(scope, globalOptionType.name), @@ -98,6 +99,35 @@ export async function renderCliType(config: CliConfig): Promise { }); } + // const globalOptions: GlobalOptions = { + // 'asset-metadata': args.assetMetadata, + // 'ca-bundle-path': args.caBundlePath, + // 'ignore-errors': args.ignoreErrors, + // 'no-color': args.noColor, + // 'path-metadata': args.pathMetadata, + // 'proxy': args.proxy, + // 'role-arn': args.roleArn, + // 'staging': args.staging, + // 'strict': args.strict, + // 'verbose': args.verbose, + // 'version-reporting': args.versionReporting, + // 'ci': args.ci, + // 'debug': args.debug, + // 'ec2creds': args.ec2creds, + // 'json': args.json, + // 'lookups': args.lookups, + // 'unstable': args.unstable, + // }; + const createCliArguments = new FreeFunction(scope, { + name: 'createCliArguments', + export: true, + returnType: Type.fromName(scope, cliArgType.name), + parameters: [ + { name: 'args', type: Type.ANY }, + ], + }); + createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config))); + const ts = new TypeScriptRenderer({ disabledEsLintRules: [EsLintRules.MAX_LEN], // the default disabled rules result in 'Definition for rule 'prettier/prettier' was not found' }).render(scope); @@ -106,6 +136,7 @@ export async function renderCliType(config: CliConfig): Promise { parser: 'typescript', printWidth: 150, singleQuote: true, + quoteProps: 'consistent', }); } @@ -148,3 +179,70 @@ function normalizeDefault(defaultValue: any, type: string): string { return generatedDefault ? JSON.stringify(generatedDefault) : 'undefined'; } } + +function buildCliArgsFunction(config: CliConfig): string { + const globalOptions = buildGlobalOptions(config); + const commandSwitch = buildCommandSwitch(config); + const cliArgs = buildCliArgs(); + return [ + globalOptions, + commandSwitch, + cliArgs, + ].join('\n'); +} + +function buildGlobalOptions(config: CliConfig): string { + const globalOptionExprs = ['const globalOptions: GlobalOptions = {']; + for (const optionName of Object.keys(config.globalOptions)) { + globalOptionExprs.push(`'${optionName}': args.${hyphenToCamelCase(optionName)},`); + } + globalOptionExprs.push('}'); + return globalOptionExprs.join('\n'); +} + +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}':`, + 'commandOptions = {', + ...buildCommandOptions(config.commands[commandName]), + '};', + `break; + `); + } + commandSwitchExprs.push('}'); + return commandSwitchExprs.join('\n'); +} + +function buildCommandOptions(options: CliAction): string[] { + const commandOptions = []; + for (const optionName of Object.keys(options.options ?? {})) { + commandOptions.push(`'${optionName}': args.${hyphenToCamelCase(optionName)},`); + } + return commandOptions; +} + +function buildCliArgs(): string { + return [ + 'const cliArguments: CliArguments = {', + '_: args._,', + 'globalOptions,', + '[args._[0]]: commandOptions', + '}', + '', + 'return cliArguments', + ].join('\n'); +} + +function hyphenToCamelCase(str: string): string { + return str + .split('-') + .map((word, index) => + index === 0 + ? word.toLowerCase() + : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(), + ) + .join(''); +} + diff --git a/tools/@aws-cdk/cli-args-gen/lib/util.ts b/tools/@aws-cdk/cli-args-gen/lib/util.ts index 047c2498283c6..2b22bb81152cb 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/util.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/util.ts @@ -1,3 +1,17 @@ +import { code, Expression } from '@cdklabs/typewriter'; + export function generateDefault(type: string) { return type === 'array' ? [] : undefined; } + +export function lit(value: any): Expression { + switch (value) { + case undefined: + return code.expr.UNDEFINED; + case null: + return code.expr.NULL; + default: + return code.expr.lit(value); + } +} + diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts index fee7fdaa61e3d..89fdbe4523cb1 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts @@ -1,7 +1,7 @@ import { $E, Expression, ExternalModule, FreeFunction, IScope, Module, SelectiveModuleImport, Statement, ThingSymbol, Type, TypeScriptRenderer, code, expr } from '@cdklabs/typewriter'; import { EsLintRules } from '@cdklabs/typewriter/lib/eslint-rules'; import * as prettier from 'prettier'; -import { generateDefault } from './util'; +import { generateDefault, lit } from './util'; import { CliConfig, CliOption, YargsOption } from './yargs-types'; // to import lodash.clonedeep properly, we would need to set esModuleInterop: true @@ -173,13 +173,3 @@ function makeEpilogue(prefix: Expression, helpers: CliHelpers) { return completeDefinition; } -function lit(value: any): Expression { - switch (value) { - case undefined: - return code.expr.UNDEFINED; - case null: - return code.expr.NULL; - default: - return code.expr.lit(value); - } -} diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts b/tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts index 6605f14eec2b7..91c23b288cd04 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/yargs-types.ts @@ -5,7 +5,7 @@ interface YargsCommand { arg?: YargsArg; } -interface CliAction extends YargsCommand { +export interface CliAction extends YargsCommand { options?: { [optionName: string]: CliOption }; } From bc6ddfdf18a77c0837763aa993db889219b225e6 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 31 Dec 2024 12:25:47 -0500 Subject: [PATCH 3/9] generate convert func in new file --- packages/aws-cdk/lib/cli-arguments.ts | 367 ++++-------------- packages/aws-cdk/lib/convert-to-cli-args.ts | 240 ++++++++++++ packages/aws-cdk/scripts/cli-args-gen.ts | 5 +- packages/aws-cdk/test/cli-arguments.test.ts | 96 ++--- tools/@aws-cdk/cli-args-gen/README.md | 7 +- .../cli-args-gen/lib/cli-args-function-gen.ts | 97 +++++ .../lib/{cli-type-gen.ts => cli-args-gen.ts} | 102 +---- tools/@aws-cdk/cli-args-gen/lib/index.ts | 3 +- .../cli-args-gen/test/cli-type-gen.test.ts | 6 +- 9 files changed, 468 insertions(+), 455 deletions(-) create mode 100644 packages/aws-cdk/lib/convert-to-cli-args.ts create mode 100644 tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts rename tools/@aws-cdk/cli-args-gen/lib/{cli-type-gen.ts => cli-args-gen.ts} (60%) diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 0db1dd88c3cea..f9c517e2da3fd 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -131,49 +131,49 @@ export interface GlobalOptions { * * @default - undefined */ - readonly 'app'?: string; + readonly app?: string; /** * Command-line for a pre-synth build * * @default - undefined */ - readonly 'build'?: string; + readonly build?: string; /** * Add contextual string parameter (KEY=VALUE) * * @default - [] */ - readonly 'context'?: Array; + readonly context?: Array; /** * Name or path of a node package that extend the CDK features. Can be specified multiple times * * @default - [] */ - readonly 'plugin'?: Array; + readonly plugin?: Array; /** * Print trace for stack warnings * * @default - undefined */ - readonly 'trace'?: boolean; + readonly trace?: boolean; /** * Do not construct stacks with warnings * * @default - undefined */ - readonly 'strict'?: boolean; + readonly strict?: boolean; /** * Perform context lookups (synthesis fails if this is disabled and context lookups need to be performed) * * @default - true */ - readonly 'lookups'?: boolean; + readonly lookups?: boolean; /** * Ignores synthesis errors, which will likely produce an invalid output @@ -187,35 +187,35 @@ export interface GlobalOptions { * * @default - false */ - readonly 'json'?: boolean; + readonly json?: boolean; /** * Show debug logs (specify multiple times to increase verbosity) * * @default - false */ - readonly 'verbose'?: boolean; + readonly verbose?: boolean; /** * Debug the CDK app. Log additional information during synthesis, such as creation stack traces of tokens (sets CDK_DEBUG, will slow down synthesis) * * @default - false */ - readonly 'debug'?: boolean; + readonly debug?: boolean; /** * Use the indicated AWS profile as the default environment * * @default - undefined */ - readonly 'profile'?: string; + readonly profile?: string; /** * Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified * * @default - undefined */ - readonly 'proxy'?: string; + readonly proxy?: string; /** * Path to CA certificate to use when validating HTTPS requests. Will read from AWS_CA_BUNDLE environment variable if not specified @@ -229,7 +229,7 @@ export interface GlobalOptions { * * @default - undefined */ - readonly 'ec2creds'?: boolean; + readonly ec2creds?: boolean; /** * Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default) @@ -264,21 +264,21 @@ export interface GlobalOptions { * * @default - true */ - readonly 'staging'?: boolean; + readonly staging?: boolean; /** * Emits the synthesized cloud assembly into a directory (default: cdk.out) * * @default - undefined */ - readonly 'output'?: string; + readonly output?: string; /** * Show relevant notices * * @default - undefined */ - readonly 'notices'?: boolean; + readonly notices?: boolean; /** * Removes colors and other style from console output @@ -292,14 +292,14 @@ export interface GlobalOptions { * * @default - undefined */ - readonly 'ci'?: boolean; + readonly ci?: boolean; /** * Opt in to unstable features. The flag indicates that the scope and API of a feature might still change. Otherwise the feature is generally production ready and fully supported. Can be specified multiple times. * * @default - [] */ - readonly 'unstable'?: Array; + readonly unstable?: Array; } /** @@ -317,7 +317,7 @@ export interface ListOptions { * * @default - false */ - readonly 'long'?: boolean; + readonly long?: boolean; /** * Display stack dependency information for each stack @@ -415,7 +415,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'qualifier'?: string; + readonly qualifier?: string; /** * Block public access configuration on CDK toolkit bucket (enabled by default) @@ -431,21 +431,21 @@ export interface BootstrapOptions { * * @default - [] */ - readonly 'tags'?: Array; + readonly tags?: Array; /** * Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet) * * @default - true */ - readonly 'execute'?: boolean; + readonly execute?: boolean; /** * The AWS account IDs that should be trusted to perform deployments into this environment (may be repeated, modern bootstrapping only) * * @default - [] */ - readonly 'trust'?: Array; + readonly trust?: Array; /** * The AWS account IDs that should be trusted to look up values in this environment (may be repeated, modern bootstrapping only) @@ -468,7 +468,7 @@ export interface BootstrapOptions { * * @default - false */ - readonly 'force'?: boolean; + readonly force?: boolean; /** * Toggle CloudFormation termination protection on the bootstrap stacks @@ -496,7 +496,7 @@ export interface BootstrapOptions { * * @default - undefined */ - readonly 'template'?: string; + readonly template?: string; /** * Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled) @@ -517,14 +517,14 @@ export interface GcOptions { * * @default - "full" */ - readonly 'action'?: string; + readonly action?: string; /** * Specify either ecr, s3, or all * * @default - "all" */ - readonly 'type'?: string; + readonly type?: string; /** * Delete assets that have been marked as isolated for this many days @@ -545,7 +545,7 @@ export interface GcOptions { * * @default - true */ - readonly 'confirm'?: boolean; + readonly confirm?: boolean; /** * The name of the CDK toolkit stack, if different from the default "CDKToolkit" @@ -566,7 +566,7 @@ export interface DeployOptions { * * @default - false */ - readonly 'all'?: boolean; + readonly all?: boolean; /** * Do not rebuild asset with the given ID. Can be specified multiple times @@ -584,7 +584,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'exclusively'?: boolean; + readonly exclusively?: boolean; /** * What security-sensitive changes need manual approval @@ -607,7 +607,7 @@ export interface DeployOptions { * * @default - [] */ - readonly 'tags'?: Array; + readonly tags?: Array; /** * Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet) (deprecated) @@ -615,7 +615,7 @@ export interface DeployOptions { * @deprecated true * @default - undefined */ - readonly 'execute'?: boolean; + readonly execute?: boolean; /** * Name of the CloudFormation change set to create (only if method is not direct) @@ -631,7 +631,7 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'method'?: string; + readonly method?: string; /** * Always deploy stack even if templates are identical @@ -640,14 +640,14 @@ export interface DeployOptions { * * @default - false */ - readonly 'force'?: boolean; + readonly force?: boolean; /** * Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE) * * @default - {} */ - readonly 'parameters'?: Array; + readonly parameters?: Array; /** * Path to file where stack outputs will be written as JSON @@ -677,21 +677,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'progress'?: string; + readonly progress?: 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 * * @default - undefined */ - readonly 'rollback'?: boolean; + readonly rollback?: boolean; /** * Attempts to perform a 'hotswap' deployment, but does not fall back to a full deployment if that is not possible. Instead, changes to any non-hotswappable properties are ignored.Do not use this in production environments * * @default - undefined */ - readonly 'hotswap'?: boolean; + readonly hotswap?: boolean; /** * Attempts to perform a 'hotswap' deployment, which skips CloudFormation and updates the resources directly, and falls back to a full deployment if that is not possible. Do not use this in production environments @@ -705,21 +705,21 @@ export interface DeployOptions { * * @default - undefined */ - readonly 'watch'?: boolean; + readonly watch?: boolean; /** * Show CloudWatch log events from all resources in the selected Stacks in the terminal. 'true' by default, use --no-logs to turn off. Only in effect if specified alongside the '--watch' option * * @default - true */ - readonly 'logs'?: boolean; + readonly logs?: boolean; /** * Maximum number of simultaneous deployments (dependency permitting) to execute. * * @default - 1 */ - readonly 'concurrency'?: number; + readonly concurrency?: number; /** * Whether to build/publish assets in parallel @@ -754,7 +754,7 @@ export interface RollbackOptions { * * @default - false */ - readonly 'all'?: boolean; + readonly all?: boolean; /** * The name of the CDK toolkit stack the environment is bootstrapped with @@ -770,7 +770,7 @@ export interface RollbackOptions { * * @default - undefined */ - readonly 'force'?: boolean; + readonly force?: boolean; /** * Whether to validate the bootstrap stack version. Defaults to 'true', disable with --no-validate-bootstrap-version. @@ -784,7 +784,7 @@ export interface RollbackOptions { * * @default - [] */ - readonly 'orphan'?: Array; + readonly orphan?: Array; } /** @@ -798,7 +798,7 @@ export interface ImportOptions { * * @default - true */ - readonly 'execute'?: boolean; + readonly execute?: boolean; /** * Name of the CloudFormation change set to create @@ -819,7 +819,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly 'rollback'?: boolean; + readonly rollback?: boolean; /** * Do not abort if the template diff includes updates or deletes. This is probably safe but we're not sure, let us know how it goes. @@ -828,7 +828,7 @@ export interface ImportOptions { * * @default - undefined */ - readonly 'force'?: boolean; + readonly force?: boolean; /** * If specified, CDK will generate a mapping of existing physical resources to CDK resources to be imported as. The mapping will be written in the given file path. No actual import operation will be performed @@ -871,7 +871,7 @@ export interface WatchOptions { * * @default - undefined */ - readonly 'exclusively'?: boolean; + readonly exclusively?: boolean; /** * Name of the CloudFormation change set to create @@ -887,7 +887,7 @@ export interface WatchOptions { * * @default - false */ - readonly 'force'?: boolean; + readonly force?: boolean; /** * The name of the existing CDK toolkit stack (only used for app using legacy synthesis) @@ -901,21 +901,21 @@ export interface WatchOptions { * * @default - undefined */ - readonly 'progress'?: string; + readonly progress?: 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 * * @default - undefined */ - readonly 'rollback'?: boolean; + readonly rollback?: boolean; /** * Attempts to perform a 'hotswap' deployment, but does not fall back to a full deployment if that is not possible. Instead, changes to any non-hotswappable properties are ignored.'true' by default, use --no-hotswap to turn off * * @default - undefined */ - readonly 'hotswap'?: boolean; + readonly hotswap?: boolean; /** * Attempts to perform a 'hotswap' deployment, which skips CloudFormation and updates the resources directly, and falls back to a full deployment if that is not possible. @@ -929,14 +929,14 @@ export interface WatchOptions { * * @default - true */ - readonly 'logs'?: boolean; + readonly logs?: boolean; /** * Maximum number of simultaneous deployments (dependency permitting) to execute. * * @default - 1 */ - readonly 'concurrency'?: number; + readonly concurrency?: number; } /** @@ -984,7 +984,7 @@ export interface DiffOptions { * * @default - undefined */ - readonly 'exclusively'?: boolean; + readonly exclusively?: boolean; /** * Number of context lines to include in arbitrary JSON diff rendering @@ -998,14 +998,14 @@ export interface DiffOptions { * * @default - undefined */ - readonly 'template'?: string; + readonly template?: string; /** * Do not filter out AWS::CDK::Metadata resources, mangled non-ASCII characters, or the CheckBootstrapVersionRule * * @default - false */ - readonly 'strict'?: boolean; + readonly strict?: boolean; /** * Only diff for broadened security changes @@ -1019,14 +1019,14 @@ export interface DiffOptions { * * @default - undefined */ - readonly 'fail'?: boolean; + readonly fail?: boolean; /** * Whether to compare against the template with Transforms already processed * * @default - false */ - readonly 'processed'?: boolean; + readonly processed?: boolean; /** * Do not print stack name and default message when there is no diff to stdout @@ -1035,7 +1035,7 @@ export interface DiffOptions { * * @default - false */ - readonly 'quiet'?: boolean; + readonly quiet?: boolean; /** * Whether to create a changeset to analyze resource replacements. In this mode, diff will use the deploy role instead of the lookup role. @@ -1092,14 +1092,14 @@ export interface InitOptions { * * @default - undefined */ - readonly 'language'?: string; + readonly language?: string; /** * List the available templates * * @default - undefined */ - readonly 'list'?: boolean; + readonly list?: boolean; /** * If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project @@ -1131,21 +1131,21 @@ export interface MigrateOptions { * * @default - "typescript" */ - readonly 'language'?: string; + readonly language?: string; /** * The account to retrieve the CloudFormation stack template from * * @default - undefined */ - readonly 'account'?: string; + readonly account?: string; /** * The region to retrieve the CloudFormation stack template from * * @default - undefined */ - readonly 'region'?: string; + readonly region?: string; /** * The path to the CloudFormation template to migrate. Use this for locally stored templates @@ -1187,14 +1187,14 @@ export interface MigrateOptions { * * @default - [] */ - readonly 'filter'?: Array; + readonly filter?: Array; /** * Use this flag to zip the generated CDK app * * @default - undefined */ - readonly 'compress'?: boolean; + readonly compress?: boolean; } /** @@ -1253,236 +1253,3 @@ export interface DocsOptions { * @struct */ export interface DoctorOptions {} - -// @ts-ignore TS6133 -export function createCliArguments(args: any): CliArguments { - const globalOptions: GlobalOptions = { - 'app': args.app, - 'build': args.build, - 'context': args.context, - 'plugin': args.plugin, - 'trace': args.trace, - 'strict': args.strict, - 'lookups': args.lookups, - 'ignore-errors': args.ignoreErrors, - 'json': args.json, - 'verbose': args.verbose, - 'debug': args.debug, - 'profile': args.profile, - 'proxy': args.proxy, - 'ca-bundle-path': args.caBundlePath, - 'ec2creds': args.ec2creds, - 'version-reporting': args.versionReporting, - 'path-metadata': args.pathMetadata, - 'asset-metadata': args.assetMetadata, - 'role-arn': args.roleArn, - 'staging': args.staging, - 'output': args.output, - 'notices': args.notices, - 'no-color': args.noColor, - 'ci': args.ci, - 'unstable': args.unstable, - }; - let commandOptions; - switch (args._[0] as Command) { - case 'list': - commandOptions = { - 'long': args.long, - 'show-dependencies': args.showDependencies, - }; - break; - - case 'synthesize': - commandOptions = { - exclusively: args.exclusively, - validation: args.validation, - quiet: args.quiet, - }; - break; - - case 'bootstrap': - commandOptions = { - 'bootstrap-bucket-name': args.bootstrapBucketName, - 'bootstrap-kms-key-id': args.bootstrapKmsKeyId, - 'example-permissions-boundary': args.examplePermissionsBoundary, - 'custom-permissions-boundary': args.customPermissionsBoundary, - 'bootstrap-customer-key': args.bootstrapCustomerKey, - 'qualifier': args.qualifier, - 'public-access-block-configuration': args.publicAccessBlockConfiguration, - 'tags': args.tags, - 'execute': args.execute, - 'trust': args.trust, - 'trust-for-lookup': args.trustForLookup, - 'cloudformation-execution-policies': args.cloudformationExecutionPolicies, - 'force': args.force, - 'termination-protection': args.terminationProtection, - 'show-template': args.showTemplate, - 'toolkit-stack-name': args.toolkitStackName, - 'template': args.template, - 'previous-parameters': args.previousParameters, - }; - break; - - case 'gc': - commandOptions = { - 'action': args.action, - 'type': args.type, - 'rollback-buffer-days': args.rollbackBufferDays, - 'created-buffer-days': args.createdBufferDays, - 'confirm': args.confirm, - 'bootstrap-stack-name': args.bootstrapStackName, - }; - break; - - case 'deploy': - commandOptions = { - 'all': args.all, - 'build-exclude': args.buildExclude, - 'exclusively': args.exclusively, - 'require-approval': args.requireApproval, - 'notification-arns': args.notificationArns, - 'tags': args.tags, - 'execute': args.execute, - 'change-set-name': args.changeSetName, - 'method': args.method, - 'force': args.force, - 'parameters': args.parameters, - 'outputs-file': args.outputsFile, - 'previous-parameters': args.previousParameters, - 'toolkit-stack-name': args.toolkitStackName, - 'progress': args.progress, - 'rollback': args.rollback, - 'hotswap': args.hotswap, - 'hotswap-fallback': args.hotswapFallback, - 'watch': args.watch, - 'logs': args.logs, - 'concurrency': args.concurrency, - 'asset-parallelism': args.assetParallelism, - 'asset-prebuild': args.assetPrebuild, - 'ignore-no-stacks': args.ignoreNoStacks, - }; - break; - - case 'rollback': - commandOptions = { - 'all': args.all, - 'toolkit-stack-name': args.toolkitStackName, - 'force': args.force, - 'validate-bootstrap-version': args.validateBootstrapVersion, - 'orphan': args.orphan, - }; - break; - - case 'import': - commandOptions = { - 'execute': args.execute, - 'change-set-name': args.changeSetName, - 'toolkit-stack-name': args.toolkitStackName, - 'rollback': args.rollback, - 'force': args.force, - 'record-resource-mapping': args.recordResourceMapping, - 'resource-mapping': args.resourceMapping, - }; - break; - - case 'watch': - commandOptions = { - 'build-exclude': args.buildExclude, - 'exclusively': args.exclusively, - 'change-set-name': args.changeSetName, - 'force': args.force, - 'toolkit-stack-name': args.toolkitStackName, - 'progress': args.progress, - 'rollback': args.rollback, - 'hotswap': args.hotswap, - 'hotswap-fallback': args.hotswapFallback, - 'logs': args.logs, - 'concurrency': args.concurrency, - }; - break; - - case 'destroy': - commandOptions = { - all: args.all, - exclusively: args.exclusively, - force: args.force, - }; - break; - - case 'diff': - commandOptions = { - 'exclusively': args.exclusively, - 'context-lines': args.contextLines, - 'template': args.template, - 'strict': args.strict, - 'security-only': args.securityOnly, - 'fail': args.fail, - 'processed': args.processed, - 'quiet': args.quiet, - 'change-set': args.changeSet, - }; - break; - - case 'metadata': - commandOptions = {}; - break; - - case 'acknowledge': - commandOptions = {}; - break; - - case 'notices': - commandOptions = { - unacknowledged: args.unacknowledged, - }; - break; - - case 'init': - commandOptions = { - 'language': args.language, - 'list': args.list, - 'generate-only': args.generateOnly, - }; - break; - - case 'migrate': - commandOptions = { - 'stack-name': args.stackName, - 'language': args.language, - 'account': args.account, - 'region': args.region, - 'from-path': args.fromPath, - 'from-stack': args.fromStack, - 'output-path': args.outputPath, - 'from-scan': args.fromScan, - 'filter': args.filter, - 'compress': args.compress, - }; - break; - - case 'context': - commandOptions = { - reset: args.reset, - force: args.force, - clear: args.clear, - }; - break; - - case 'docs': - commandOptions = { - browser: args.browser, - }; - break; - - case 'doctor': - commandOptions = {}; - break; - } - const cliArguments: CliArguments = { - _: args._, - globalOptions, - [args._[0]]: commandOptions, - }; - - return cliArguments; -} diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts new file mode 100644 index 0000000000000..f7bf1b68a2f72 --- /dev/null +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -0,0 +1,240 @@ +// ------------------------------------------------------------------------------------------- +// GENERATED FROM packages/aws-cdk/lib/config.ts. +// Do not edit by hand; all changes will be overwritten at build time from the config file. +// ------------------------------------------------------------------------------------------- +/* eslint-disable @stylistic/max-len */ +import { CliArguments, GlobalOptions } from './cli-arguments'; +import { Command } from './settings'; + +// @ts-ignore TS6133 +export function convertToCliArgs(args: any): CliArguments { + const globalOptions: GlobalOptions = { + app: args.app, + build: args.build, + context: args.context, + plugin: args.plugin, + trace: args.trace, + strict: args.strict, + lookups: args.lookups, + ignoreErrors: args.ignoreErrors, + json: args.json, + verbose: args.verbose, + debug: args.debug, + profile: args.profile, + proxy: args.proxy, + caBundlePath: args.caBundlePath, + ec2creds: args.ec2creds, + versionReporting: args.versionReporting, + pathMetadata: args.pathMetadata, + assetMetadata: args.assetMetadata, + roleArn: args.roleArn, + staging: args.staging, + output: args.output, + notices: args.notices, + noColor: args.noColor, + ci: args.ci, + unstable: args.unstable, + }; + let commandOptions; + switch (args._[0] as Command) { + case 'list': + commandOptions = { + long: args.long, + showDependencies: args.showDependencies, + }; + break; + + case 'synthesize': + commandOptions = { + exclusively: args.exclusively, + validation: args.validation, + quiet: args.quiet, + }; + break; + + case 'bootstrap': + commandOptions = { + bootstrapBucketName: args.bootstrapBucketName, + bootstrapKmsKeyId: args.bootstrapKmsKeyId, + examplePermissionsBoundary: args.examplePermissionsBoundary, + customPermissionsBoundary: args.customPermissionsBoundary, + bootstrapCustomerKey: args.bootstrapCustomerKey, + qualifier: args.qualifier, + publicAccessBlockConfiguration: args.publicAccessBlockConfiguration, + tags: args.tags, + execute: args.execute, + trust: args.trust, + trustForLookup: args.trustForLookup, + cloudformationExecutionPolicies: args.cloudformationExecutionPolicies, + force: args.force, + terminationProtection: args.terminationProtection, + showTemplate: args.showTemplate, + toolkitStackName: args.toolkitStackName, + template: args.template, + previousParameters: args.previousParameters, + }; + break; + + case 'gc': + commandOptions = { + action: args.action, + type: args.type, + rollbackBufferDays: args.rollbackBufferDays, + createdBufferDays: args.createdBufferDays, + confirm: args.confirm, + bootstrapStackName: args.bootstrapStackName, + }; + break; + + case 'deploy': + commandOptions = { + all: args.all, + buildExclude: args.buildExclude, + exclusively: args.exclusively, + requireApproval: args.requireApproval, + notificationArns: args.notificationArns, + tags: args.tags, + execute: args.execute, + changeSetName: args.changeSetName, + method: args.method, + force: args.force, + parameters: args.parameters, + outputsFile: args.outputsFile, + previousParameters: args.previousParameters, + toolkitStackName: args.toolkitStackName, + progress: args.progress, + rollback: args.rollback, + hotswap: args.hotswap, + hotswapFallback: args.hotswapFallback, + watch: args.watch, + logs: args.logs, + concurrency: args.concurrency, + assetParallelism: args.assetParallelism, + assetPrebuild: args.assetPrebuild, + ignoreNoStacks: args.ignoreNoStacks, + }; + break; + + case 'rollback': + commandOptions = { + all: args.all, + toolkitStackName: args.toolkitStackName, + force: args.force, + validateBootstrapVersion: args.validateBootstrapVersion, + orphan: args.orphan, + }; + break; + + case 'import': + commandOptions = { + execute: args.execute, + changeSetName: args.changeSetName, + toolkitStackName: args.toolkitStackName, + rollback: args.rollback, + force: args.force, + recordResourceMapping: args.recordResourceMapping, + resourceMapping: args.resourceMapping, + }; + break; + + case 'watch': + commandOptions = { + buildExclude: args.buildExclude, + exclusively: args.exclusively, + changeSetName: args.changeSetName, + force: args.force, + toolkitStackName: args.toolkitStackName, + progress: args.progress, + rollback: args.rollback, + hotswap: args.hotswap, + hotswapFallback: args.hotswapFallback, + logs: args.logs, + concurrency: args.concurrency, + }; + break; + + case 'destroy': + commandOptions = { + all: args.all, + exclusively: args.exclusively, + force: args.force, + }; + break; + + case 'diff': + commandOptions = { + exclusively: args.exclusively, + contextLines: args.contextLines, + template: args.template, + strict: args.strict, + securityOnly: args.securityOnly, + fail: args.fail, + processed: args.processed, + quiet: args.quiet, + changeSet: args.changeSet, + }; + break; + + case 'metadata': + commandOptions = {}; + break; + + case 'acknowledge': + commandOptions = {}; + break; + + case 'notices': + commandOptions = { + unacknowledged: args.unacknowledged, + }; + break; + + case 'init': + commandOptions = { + language: args.language, + list: args.list, + generateOnly: args.generateOnly, + }; + break; + + case 'migrate': + commandOptions = { + stackName: args.stackName, + language: args.language, + account: args.account, + region: args.region, + fromPath: args.fromPath, + fromStack: args.fromStack, + outputPath: args.outputPath, + fromScan: args.fromScan, + filter: args.filter, + compress: args.compress, + }; + break; + + case 'context': + commandOptions = { + reset: args.reset, + force: args.force, + clear: args.clear, + }; + break; + + case 'docs': + commandOptions = { + browser: args.browser, + }; + break; + + case 'doctor': + commandOptions = {}; + break; + } + const cliArguments: CliArguments = { + _: args._, + globalOptions, + [args._[0]]: commandOptions, + }; + + return cliArguments; +} diff --git a/packages/aws-cdk/scripts/cli-args-gen.ts b/packages/aws-cdk/scripts/cli-args-gen.ts index cde589928e1a4..68d53eeff0597 100644 --- a/packages/aws-cdk/scripts/cli-args-gen.ts +++ b/packages/aws-cdk/scripts/cli-args-gen.ts @@ -1,11 +1,12 @@ import * as fs from 'fs'; // eslint-disable-next-line import/no-extraneous-dependencies -import { renderYargs, renderCliType } from '@aws-cdk/cli-args-gen'; +import { renderYargs, renderCliArgsType, renderCliArgsFunc } from '@aws-cdk/cli-args-gen'; import { makeConfig, YARGS_HELPERS } from '../lib/config'; async function main() { fs.writeFileSync('./lib/parse-command-line-arguments.ts', await renderYargs(await makeConfig(), YARGS_HELPERS)); - fs.writeFileSync('./lib/cli-arguments.ts', await renderCliType(await makeConfig())); + fs.writeFileSync('./lib/cli-arguments.ts', await renderCliArgsType(await makeConfig())); + fs.writeFileSync('./lib/convert-to-cli-args.ts', await renderCliArgsFunc(await makeConfig())); } main().then(() => { diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index bf89717ac816a..cf2807567c110 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -1,4 +1,4 @@ -import { createCliArguments } from '../lib/cli-arguments'; +import { convertToCliArgs } from '../lib/convert-to-cli-args'; test('yargs object can be converted to cli arguments', async () => { // This input represents what would come out of yargs, i.e. @@ -48,59 +48,59 @@ test('yargs object can be converted to cli arguments', async () => { 'ignoreNoStacks': false, }; - const result = createCliArguments(input); + const result = convertToCliArgs(input); expect(result).toEqual({ _: ['deploy'], globalOptions: { - 'app': undefined, - 'asset-metadata': undefined, - 'build': undefined, - 'ca-bundle-path': undefined, - 'context': undefined, - 'ignore-errors': false, - 'no-color': false, - 'path-metadata': undefined, - 'proxy': undefined, - 'role-arn': undefined, - 'staging': true, - 'strict': undefined, - 'verbose': 1, - 'version-reporting': undefined, - 'ci': false, - 'debug': false, - 'ec2creds': undefined, - 'json': false, - 'lookups': true, - 'unstable': [], - 'notices': undefined, - 'output': undefined, + app: undefined, + assetMetadata: undefined, + build: undefined, + caBundlePath: undefined, + context: undefined, + ignoreErrors: false, + noColor: false, + pathMetadata: undefined, + proxy: undefined, + roleArn: undefined, + staging: true, + strict: undefined, + verbose: 1, + versionReporting: undefined, + ci: false, + debug: false, + ec2creds: undefined, + json: false, + lookups: true, + unstable: [], + notices: undefined, + output: undefined, }, deploy: { - 'all': false, - 'asset-parallelism': undefined, - 'asset-prebuild': true, - 'build-exclude': [], - 'change-set-name': undefined, - 'concurrency': 1, - 'execute': undefined, - 'exclusively': undefined, - 'force': false, - 'hotswap': undefined, - 'hotswap-fallback': undefined, - 'ignore-no-stacks': false, - 'logs': true, - 'method': undefined, - 'notification-arns': ['[]'], - 'outputs-file': undefined, - 'parameters': [{}], - 'previous-parameters': true, - 'progress': undefined, - 'require-approval': undefined, - 'rollback': undefined, - 'tags': undefined, - 'toolkit-stack-name': undefined, - 'watch': undefined, + all: false, + assetParallelism: undefined, + assetPrebuild: true, + buildExclude: [], + changeSetName: undefined, + concurrency: 1, + execute: undefined, + exclusively: undefined, + force: false, + hotswap: undefined, + hotswapFallback: undefined, + ignoreNoStacks: false, + logs: true, + method: undefined, + notificationArns: ['[]'], + outputsFile: undefined, + parameters: [{}], + previousParameters: true, + progress: undefined, + requireApproval: undefined, + rollback: undefined, + tags: undefined, + toolkitStackName: undefined, + watch: undefined, }, }); }); diff --git a/tools/@aws-cdk/cli-args-gen/README.md b/tools/@aws-cdk/cli-args-gen/README.md index d3a6396495bf8..8915e8d8de23b 100644 --- a/tools/@aws-cdk/cli-args-gen/README.md +++ b/tools/@aws-cdk/cli-args-gen/README.md @@ -1,8 +1,11 @@ # cli-args-gen Generates CDK CLI configurations from the source of truth in `packages/aws-cdk/lib/config.ts`. -Currently generates `yargs` config into `packages/aws-cdk/lib/parse-command-line-arguments.ts` and -strongly-typed CLI arguments interface into `packages/aws-cdk-lib/cli-arguments.ts`. +Currently generates the following files: + +- `packages/aws-cdk/lib/parse-command-line-arguments.ts`: `yargs` config. +- `packages/aws-cdk-lib/cli-arguments.ts`: strongly typed `CliArguments` interface. +- `packages/aws-cdk-lib/convert-to-cli-args.ts`: converts the `any` returned by `yargs` to `CliArguments`. ## Usage 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 new file mode 100644 index 0000000000000..67aa076528238 --- /dev/null +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts @@ -0,0 +1,97 @@ +import { code, FreeFunction, Module, SelectiveModuleImport, Type, TypeScriptRenderer } from '@cdklabs/typewriter'; +import { EsLintRules } from '@cdklabs/typewriter/lib/eslint-rules'; +import * as prettier from 'prettier'; +import { kebabToCamelCase } from './util'; +import { CliAction, CliConfig } from './yargs-types'; + +export async function renderCliArgsFunc(config: CliConfig): Promise { + const scope = new Module('aws-cdk'); + + scope.documentation.push( '-------------------------------------------------------------------------------------------'); + scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); + scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); + scope.documentation.push('-------------------------------------------------------------------------------------------'); + + scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions'])); + const cliArgType = Type.fromName(scope, 'CliArguments'); + + scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command'])); + + const createCliArguments = new FreeFunction(scope, { + name: 'convertToCliArgs', + export: true, + returnType: cliArgType, + parameters: [ + { name: 'args', type: Type.ANY }, + ], + }); + createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config))); + + const ts = new TypeScriptRenderer({ + disabledEsLintRules: [EsLintRules.MAX_LEN], // the default disabled rules result in 'Definition for rule 'prettier/prettier' was not found' + }).render(scope); + + return prettier.format(ts, { + parser: 'typescript', + printWidth: 150, + singleQuote: true, + quoteProps: 'consistent', + }); +} + +function buildCliArgsFunction(config: CliConfig): string { + const globalOptions = buildGlobalOptions(config); + const commandSwitch = buildCommandSwitch(config); + const cliArgs = buildCliArgs(); + return [ + globalOptions, + commandSwitch, + cliArgs, + ].join('\n'); +} + +function buildGlobalOptions(config: CliConfig): string { + const globalOptionExprs = ['const globalOptions: GlobalOptions = {']; + for (const optionName of Object.keys(config.globalOptions)) { + const name = kebabToCamelCase(optionName); + globalOptionExprs.push(`'${name}': args.${name},`); + } + globalOptionExprs.push('}'); + return globalOptionExprs.join('\n'); +} + +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}':`, + 'commandOptions = {', + ...buildCommandOptions(config.commands[commandName]), + '};', + `break; + `); + } + commandSwitchExprs.push('}'); + return commandSwitchExprs.join('\n'); +} + +function buildCommandOptions(options: CliAction): string[] { + const commandOptions: string[] = []; + for (const optionName of Object.keys(options.options ?? {})) { + const name = kebabToCamelCase(optionName); + commandOptions.push(`'${name}': args.${name},`); + } + return commandOptions; +} + +function buildCliArgs(): string { + return [ + 'const cliArguments: CliArguments = {', + '_: args._,', + 'globalOptions,', + '[args._[0]]: commandOptions', + '}', + '', + 'return cliArguments', + ].join('\n'); +} diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts similarity index 60% rename from tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts rename to tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts index fd79debd6dfd4..139e4dd7a6c9d 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-type-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts @@ -1,10 +1,10 @@ -import { code, FreeFunction, Module, SelectiveModuleImport, StructType, Type, TypeScriptRenderer } from '@cdklabs/typewriter'; +import { Module, SelectiveModuleImport, StructType, Type, TypeScriptRenderer } from '@cdklabs/typewriter'; import { EsLintRules } from '@cdklabs/typewriter/lib/eslint-rules'; import * as prettier from 'prettier'; import { generateDefault, kebabToCamelCase, kebabToPascal } from './util'; -import { CliAction, CliConfig } from './yargs-types'; +import { CliConfig } from './yargs-types'; -export async function renderCliType(config: CliConfig): Promise { +export async function renderCliArgsType(config: CliConfig): Promise { const scope = new Module('aws-cdk'); scope.documentation.push( '-------------------------------------------------------------------------------------------'); @@ -99,35 +99,6 @@ export async function renderCliType(config: CliConfig): Promise { }); } - // const globalOptions: GlobalOptions = { - // 'asset-metadata': args.assetMetadata, - // 'ca-bundle-path': args.caBundlePath, - // 'ignore-errors': args.ignoreErrors, - // 'no-color': args.noColor, - // 'path-metadata': args.pathMetadata, - // 'proxy': args.proxy, - // 'role-arn': args.roleArn, - // 'staging': args.staging, - // 'strict': args.strict, - // 'verbose': args.verbose, - // 'version-reporting': args.versionReporting, - // 'ci': args.ci, - // 'debug': args.debug, - // 'ec2creds': args.ec2creds, - // 'json': args.json, - // 'lookups': args.lookups, - // 'unstable': args.unstable, - // }; - const createCliArguments = new FreeFunction(scope, { - name: 'createCliArguments', - export: true, - returnType: Type.fromName(scope, cliArgType.name), - parameters: [ - { name: 'args', type: Type.ANY }, - ], - }); - createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config))); - const ts = new TypeScriptRenderer({ disabledEsLintRules: [EsLintRules.MAX_LEN], // the default disabled rules result in 'Definition for rule 'prettier/prettier' was not found' }).render(scope); @@ -172,70 +143,3 @@ function normalizeDefault(defaultValue: any, type: string): string { return generatedDefault ? JSON.stringify(generatedDefault) : 'undefined'; } } - -function buildCliArgsFunction(config: CliConfig): string { - const globalOptions = buildGlobalOptions(config); - const commandSwitch = buildCommandSwitch(config); - const cliArgs = buildCliArgs(); - return [ - globalOptions, - commandSwitch, - cliArgs, - ].join('\n'); -} - -function buildGlobalOptions(config: CliConfig): string { - const globalOptionExprs = ['const globalOptions: GlobalOptions = {']; - for (const optionName of Object.keys(config.globalOptions)) { - globalOptionExprs.push(`'${optionName}': args.${hyphenToCamelCase(optionName)},`); - } - globalOptionExprs.push('}'); - return globalOptionExprs.join('\n'); -} - -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}':`, - 'commandOptions = {', - ...buildCommandOptions(config.commands[commandName]), - '};', - `break; - `); - } - commandSwitchExprs.push('}'); - return commandSwitchExprs.join('\n'); -} - -function buildCommandOptions(options: CliAction): string[] { - const commandOptions = []; - for (const optionName of Object.keys(options.options ?? {})) { - commandOptions.push(`'${optionName}': args.${hyphenToCamelCase(optionName)},`); - } - return commandOptions; -} - -function buildCliArgs(): string { - return [ - 'const cliArguments: CliArguments = {', - '_: args._,', - 'globalOptions,', - '[args._[0]]: commandOptions', - '}', - '', - 'return cliArguments', - ].join('\n'); -} - -function hyphenToCamelCase(str: string): string { - return str - .split('-') - .map((word, index) => - index === 0 - ? word.toLowerCase() - : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(), - ) - .join(''); -} - diff --git a/tools/@aws-cdk/cli-args-gen/lib/index.ts b/tools/@aws-cdk/cli-args-gen/lib/index.ts index 7b8f3eea63ace..6dfee4beeac38 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/index.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/index.ts @@ -1,3 +1,4 @@ export * from './yargs-gen'; export * from './yargs-types'; -export * from './cli-type-gen'; +export * from './cli-args-gen'; +export * from './cli-args-function-gen'; 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 a3d119fc5fd89..cdae7d1a6d967 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 @@ -1,4 +1,4 @@ -import { CliConfig, renderCliType } from '../lib'; +import { CliConfig, renderCliArgsType } from '../lib'; describe('render', () => { test('can generate CliArguments type', async () => { @@ -38,7 +38,7 @@ describe('render', () => { }, }; - expect(await renderCliType(config)).toMatchInlineSnapshot(` + expect(await renderCliArgsType(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. @@ -140,7 +140,7 @@ describe('render', () => { globalOptions: {}, }; - expect(await renderCliType(config)).toMatchInlineSnapshot(` + expect(await renderCliArgsType(config)).toMatchInlineSnapshot(` "// ------------------------------------------------------------------------------------------- // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. From d606b178ef9a2a6dbafb58618e4fa2e72d7f0b33 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 31 Dec 2024 12:40:16 -0500 Subject: [PATCH 4/9] add test --- .../test/cli-args-function-gen.test.ts | 77 +++++++++++++++++++ ...-type-gen.test.ts => cli-args-gen.test.ts} | 0 2 files changed, 77 insertions(+) create mode 100644 tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts rename tools/@aws-cdk/cli-args-gen/test/{cli-type-gen.test.ts => cli-args-gen.test.ts} (100%) 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 new file mode 100644 index 0000000000000..d05b457f2e018 --- /dev/null +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-function-gen.test.ts @@ -0,0 +1,77 @@ +import { CliConfig, renderCliArgsFunc } from '../lib'; + +describe('render', () => { + test('can generate conversion function', async () => { + const config: CliConfig = { + globalOptions: { + app: { + type: 'string', + desc: 'REQUIRED: Command-line for executing your app', + }, + debug: { + type: 'boolean', + desc: 'Enable debug logging', + default: false, + }, + context: { + default: [], + type: 'array', + alias: 'c', + desc: 'context values', + }, + plugin: { + type: 'array', + desc: 'plugins to load', + }, + }, + commands: { + deploy: { + description: 'Deploy a stack', + options: { + all: { + type: 'boolean', + desc: 'Deploy all stacks', + default: false, + }, + }, + }, + }, + }; + + expect(await renderCliArgsFunc(config)).toMatchInlineSnapshot(` + "// ------------------------------------------------------------------------------------------- + // GENERATED FROM packages/aws-cdk/lib/config.ts. + // Do not edit by hand; all changes will be overwritten at build time from the config file. + // ------------------------------------------------------------------------------------------- + /* eslint-disable @stylistic/max-len */ + import { CliArguments, GlobalOptions } from './cli-arguments'; + import { Command } from './settings'; + + // @ts-ignore TS6133 + export function convertToCliArgs(args: any): CliArguments { + const globalOptions: GlobalOptions = { + app: args.app, + debug: args.debug, + context: args.context, + plugin: args.plugin, + }; + let commandOptions; + switch (args._[0] as Command) { + case 'deploy': + commandOptions = { + all: args.all, + }; + break; + } + const cliArguments: CliArguments = { + _: args._, + globalOptions, + [args._[0]]: commandOptions, + }; + + return cliArguments; + } + " +`); + }); +}); diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts similarity index 100% rename from tools/@aws-cdk/cli-args-gen/test/cli-type-gen.test.ts rename to tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts From 795bf08b18d80cdafa09b20d50734bd846f6c0d2 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 31 Dec 2024 16:53:54 -0500 Subject: [PATCH 5/9] update codecov to exclude generated files --- codecov.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index e21d3c0ecbf7d..8cfefac2290da 100644 --- a/codecov.yml +++ b/codecov.yml @@ -36,5 +36,7 @@ component_management: # https://docs.codecov.com/docs/ignoring-paths ignore: - - packages/aws-cdk/lib/parse-command-line-arguments.ts # this file is generated and some lines cannot be tested + - packages/aws-cdk/lib/parse-command-line-arguments.ts # we generate this file and the generation is tested. + - packages/aws-cdk/lib/cli-arguments.ts # we generate this file and the generation is tested. + - packages/aws-cdk/lib/convert-to-cli-args.ts # we generate this file and the generation is tested. - packages/aws-cdk/lib/cli.ts # we integ test this file From 1510105d3568d697245c3dd0826ce2b9e8bee72f Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Thu, 2 Jan 2025 11:22:05 -0500 Subject: [PATCH 6/9] test uses parseCommandLineArguments --- packages/aws-cdk/test/cli-arguments.test.ts | 59 ++++----------------- 1 file changed, 9 insertions(+), 50 deletions(-) diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index cf2807567c110..b3bb4e319d2d8 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -1,52 +1,8 @@ import { convertToCliArgs } from '../lib/convert-to-cli-args'; +import { parseCommandLineArguments } from '../lib/parse-command-line-arguments'; test('yargs object can be converted to cli arguments', async () => { - // This input represents what would come out of yargs, i.e. - // await parseCommandLineArguments(args); - const input = { - '_': ['deploy'], - 'notification-arns': ['[]'], - 'notificationArns': ['[]'], - 'v': 1, - 'verbose': 1, - 'lookups': true, - 'ignore-errors': false, - 'ignoreErrors': false, - 'json': false, - 'j': false, - 'debug': false, - 'ec2creds': undefined, - 'i': undefined, - 'version-reporting': undefined, - 'versionReporting': undefined, - 'path-metadata': undefined, - 'pathMetadata': undefined, - 'asset-metadata': undefined, - 'assetMetadata': undefined, - 'role-arn': undefined, - 'r': undefined, - 'roleArn': undefined, - 'staging': true, - 'no-color': false, - 'noColor': false, - 'ci': false, - 'unstable': [], - 'all': false, - 'build-exclude': [], - 'E': [], - 'buildExclude': [], - 'force': false, - 'f': false, - 'parameters': [{}], - 'previous-parameters': true, - 'previousParameters': true, - 'logs': true, - 'concurrency': 1, - 'asset-prebuild': true, - 'assetPrebuild': true, - 'ignore-no-stacks': false, - 'ignoreNoStacks': false, - }; + const input = await parseCommandLineArguments(['deploy', '-R', '-v']); const result = convertToCliArgs(input); @@ -57,10 +13,12 @@ test('yargs object can be converted to cli arguments', async () => { assetMetadata: undefined, build: undefined, caBundlePath: undefined, - context: undefined, + context: [], ignoreErrors: false, noColor: false, pathMetadata: undefined, + plugin: [], + profile: undefined, proxy: undefined, roleArn: undefined, staging: true, @@ -72,6 +30,7 @@ test('yargs object can be converted to cli arguments', async () => { ec2creds: undefined, json: false, lookups: true, + trace: undefined, unstable: [], notices: undefined, output: undefined, @@ -91,14 +50,14 @@ test('yargs object can be converted to cli arguments', async () => { ignoreNoStacks: false, logs: true, method: undefined, - notificationArns: ['[]'], + notificationArns: undefined, outputsFile: undefined, parameters: [{}], previousParameters: true, progress: undefined, requireApproval: undefined, - rollback: undefined, - tags: undefined, + rollback: false, + tags: [], toolkitStackName: undefined, watch: undefined, }, From ce2b2e55cfe3c7a463be09081cf5f51f9e9b08af Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Thu, 2 Jan 2025 11:35:52 -0500 Subject: [PATCH 7/9] use codecov ignore file --- codecov.yml | 3 --- packages/aws-cdk/lib/cli-arguments.ts | 1 + packages/aws-cdk/lib/convert-to-cli-args.ts | 2 ++ packages/aws-cdk/lib/parse-command-line-arguments.ts | 1 + tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts | 1 + tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts | 1 + tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts | 2 +- 7 files changed, 7 insertions(+), 4 deletions(-) diff --git a/codecov.yml b/codecov.yml index 8cfefac2290da..b73c1ed223090 100644 --- a/codecov.yml +++ b/codecov.yml @@ -36,7 +36,4 @@ component_management: # https://docs.codecov.com/docs/ignoring-paths ignore: - - packages/aws-cdk/lib/parse-command-line-arguments.ts # we generate this file and the generation is tested. - - packages/aws-cdk/lib/cli-arguments.ts # we generate this file and the generation is tested. - - packages/aws-cdk/lib/convert-to-cli-args.ts # we generate this file and the generation is tested. - packages/aws-cdk/lib/cli.ts # we integ test this file diff --git a/packages/aws-cdk/lib/cli-arguments.ts b/packages/aws-cdk/lib/cli-arguments.ts index 126eee3ad4f94..ea957cd036765 100644 --- a/packages/aws-cdk/lib/cli-arguments.ts +++ b/packages/aws-cdk/lib/cli-arguments.ts @@ -2,6 +2,7 @@ // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- +// istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Command } from './settings'; diff --git a/packages/aws-cdk/lib/convert-to-cli-args.ts b/packages/aws-cdk/lib/convert-to-cli-args.ts index f7bf1b68a2f72..a55fa39092195 100644 --- a/packages/aws-cdk/lib/convert-to-cli-args.ts +++ b/packages/aws-cdk/lib/convert-to-cli-args.ts @@ -2,6 +2,7 @@ // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- +// istanbul ignore file /* eslint-disable @stylistic/max-len */ import { CliArguments, GlobalOptions } from './cli-arguments'; import { Command } from './settings'; @@ -97,6 +98,7 @@ export function convertToCliArgs(args: any): CliArguments { execute: args.execute, changeSetName: args.changeSetName, method: args.method, + importExistingResources: args.importExistingResources, force: args.force, parameters: args.parameters, outputsFile: args.outputsFile, diff --git a/packages/aws-cdk/lib/parse-command-line-arguments.ts b/packages/aws-cdk/lib/parse-command-line-arguments.ts index b0d4f3060024e..88c379a035dea 100644 --- a/packages/aws-cdk/lib/parse-command-line-arguments.ts +++ b/packages/aws-cdk/lib/parse-command-line-arguments.ts @@ -2,6 +2,7 @@ // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- +// istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; 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 67aa076528238..e7e4a8f7c57ac 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 @@ -11,6 +11,7 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); + scope.documentation.push('istanbul ignore file'); scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions'])); const cliArgType = Type.fromName(scope, 'CliArguments'); diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts index 139e4dd7a6c9d..bea1e8e99849c 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts @@ -11,6 +11,7 @@ export async function renderCliArgsType(config: CliConfig): Promise { scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); + scope.documentation.push('istanbul ignore file'); const cliArgType = new StructType(scope, { export: true, diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts index 89fdbe4523cb1..b8f88654af9fe 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts @@ -27,7 +27,7 @@ export async function renderYargs(config: CliConfig, helpers: CliHelpers): Promi scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - + scope.documentation.push('istanbul ignore file'); scope.addImport(new SelectiveModuleImport(scope, 'yargs', ['Argv'])); helpers.import(scope, 'helpers'); From be39bd39b7ac7adf5182705cbcee2697f9261f21 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Thu, 2 Jan 2025 12:08:34 -0500 Subject: [PATCH 8/9] fix tests --- packages/aws-cdk/test/cli-arguments.test.ts | 5 +++-- .../cli-args-gen/test/cli-args-function-gen.test.ts | 3 ++- tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts | 6 ++++-- tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts | 9 ++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/aws-cdk/test/cli-arguments.test.ts b/packages/aws-cdk/test/cli-arguments.test.ts index b3bb4e319d2d8..d749efb2785bd 100644 --- a/packages/aws-cdk/test/cli-arguments.test.ts +++ b/packages/aws-cdk/test/cli-arguments.test.ts @@ -2,7 +2,7 @@ import { convertToCliArgs } from '../lib/convert-to-cli-args'; import { parseCommandLineArguments } from '../lib/parse-command-line-arguments'; test('yargs object can be converted to cli arguments', async () => { - const input = await parseCommandLineArguments(['deploy', '-R', '-v']); + const input = await parseCommandLineArguments(['deploy', '-R', '-v', '--ci']); const result = convertToCliArgs(input); @@ -25,7 +25,7 @@ test('yargs object can be converted to cli arguments', async () => { strict: undefined, verbose: 1, versionReporting: undefined, - ci: false, + ci: true, debug: false, ec2creds: undefined, json: false, @@ -48,6 +48,7 @@ test('yargs object can be converted to cli arguments', async () => { hotswap: undefined, hotswapFallback: undefined, ignoreNoStacks: false, + importExistingResources: false, logs: true, method: undefined, notificationArns: undefined, 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 d05b457f2e018..247b11e7fd4f2 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 @@ -43,6 +43,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { CliArguments, GlobalOptions } from './cli-arguments'; import { Command } from './settings'; @@ -72,6 +73,6 @@ describe('render', () => { return cliArguments; } " -`); + `); }); }); diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts index cdae7d1a6d967..9c8c9cd66c5da 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts @@ -43,6 +43,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Command } from './settings'; @@ -117,7 +118,7 @@ describe('render', () => { readonly all?: boolean; } " - `); + `); }); test('special notification-arn option gets undefined default', async () => { @@ -145,6 +146,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Command } from './settings'; @@ -198,6 +200,6 @@ describe('render', () => { readonly otherArray?: Array; } " - `); + `); }); }); diff --git a/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts index 75540361fcc3a..f30a8fc51e00e 100644 --- a/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts @@ -28,6 +28,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -69,7 +70,7 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); test('can generate negativeAlias', async () => { @@ -95,6 +96,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -127,7 +129,7 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); test('can pass-through expression unchanged', async () => { @@ -180,6 +182,7 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- + // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -217,6 +220,6 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); }); From 7c310b2c17f2a8db0c4d1d4e66987f16b2ad8983 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Thu, 2 Jan 2025 12:43:34 -0500 Subject: [PATCH 9/9] jest ignore files --- packages/aws-cdk/jest.config.js | 4 ++++ tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts | 1 - tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts | 1 - tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts | 2 +- .../cli-args-gen/test/cli-args-function-gen.test.ts | 1 - tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts | 6 ++---- tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts | 9 +++------ 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/aws-cdk/jest.config.js b/packages/aws-cdk/jest.config.js index f26c2c7b13c4e..f82ca932d08a3 100644 --- a/packages/aws-cdk/jest.config.js +++ b/packages/aws-cdk/jest.config.js @@ -17,6 +17,10 @@ const config = { ...baseConfig.coveragePathIgnorePatterns, // Mostly wrappers around the SDK, which get mocked in unit tests "/lib/api/aws-auth/sdk.ts", + // Files generated by cli-args-gen + "/lib/parse-command-line-arguments.ts", + "/lib/cli-arguments.ts", + "/lib/convert-to-cli-args.ts", ], // We have many tests here that commonly time out 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 e7e4a8f7c57ac..67aa076528238 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 @@ -11,7 +11,6 @@ export async function renderCliArgsFunc(config: CliConfig): Promise { scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - scope.documentation.push('istanbul ignore file'); scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions'])); const cliArgType = Type.fromName(scope, 'CliArguments'); diff --git a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts index bea1e8e99849c..139e4dd7a6c9d 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/cli-args-gen.ts @@ -11,7 +11,6 @@ export async function renderCliArgsType(config: CliConfig): Promise { scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - scope.documentation.push('istanbul ignore file'); const cliArgType = new StructType(scope, { export: true, diff --git a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts index b8f88654af9fe..89fdbe4523cb1 100644 --- a/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts +++ b/tools/@aws-cdk/cli-args-gen/lib/yargs-gen.ts @@ -27,7 +27,7 @@ export async function renderYargs(config: CliConfig, helpers: CliHelpers): Promi scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.'); scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.'); scope.documentation.push('-------------------------------------------------------------------------------------------'); - scope.documentation.push('istanbul ignore file'); + scope.addImport(new SelectiveModuleImport(scope, 'yargs', ['Argv'])); helpers.import(scope, 'helpers'); 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 247b11e7fd4f2..2f5f1a96e57ed 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 @@ -43,7 +43,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { CliArguments, GlobalOptions } from './cli-arguments'; import { Command } from './settings'; diff --git a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts index 9c8c9cd66c5da..cdae7d1a6d967 100644 --- a/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/cli-args-gen.test.ts @@ -43,7 +43,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Command } from './settings'; @@ -118,7 +117,7 @@ describe('render', () => { readonly all?: boolean; } " - `); + `); }); test('special notification-arn option gets undefined default', async () => { @@ -146,7 +145,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Command } from './settings'; @@ -200,6 +198,6 @@ describe('render', () => { readonly otherArray?: Array; } " - `); + `); }); }); diff --git a/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts b/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts index f30a8fc51e00e..75540361fcc3a 100644 --- a/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts +++ b/tools/@aws-cdk/cli-args-gen/test/yargs-gen.test.ts @@ -28,7 +28,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -70,7 +69,7 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); test('can generate negativeAlias', async () => { @@ -96,7 +95,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -129,7 +127,7 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); test('can pass-through expression unchanged', async () => { @@ -182,7 +180,6 @@ describe('render', () => { // GENERATED FROM packages/aws-cdk/lib/config.ts. // Do not edit by hand; all changes will be overwritten at build time from the config file. // ------------------------------------------------------------------------------------------- - // istanbul ignore file /* eslint-disable @stylistic/max-len */ import { Argv } from 'yargs'; import * as helpers from './util/yargs-helpers'; @@ -220,6 +217,6 @@ describe('render', () => { } // eslint-disable-next-line @typescript-eslint/no-require-imports const yargs = require('yargs'); " - `); + `); }); });