Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): rename cli-args-gen into user-input-gen #32821

Merged
merged 12 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws-cdk.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"name": "aws-custom-resource-sdk-adapter",
"rootPath": "packages/@aws-cdk/aws-custom-resource-sdk-adapter"
},
{ "name": "cli-args-gen", "rootPath": "tools/@aws-cdk/cli-args-gen" }
{ "name": "user-input-gen", "rootPath": "tools/@aws-cdk/user-input-gen" }
]
},
"extensions": {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"packages/@aws-cdk-testing/*",
"packages/@aws-cdk/*/lambda-packages/*",
"tools/@aws-cdk/cdk-build-tools",
"tools/@aws-cdk/cli-args-gen",
"tools/@aws-cdk/user-input-gen",
"tools/@aws-cdk/cdk-release",
"tools/@aws-cdk/node-bundle",
"tools/@aws-cdk/pkglint",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"packages/@aws-cdk-testing/*",
"packages/@aws-cdk/*/lambda-packages/*",
"tools/@aws-cdk/cdk-build-tools",
"tools/@aws-cdk/cli-args-gen",
"tools/@aws-cdk/user-input-gen",
"tools/@aws-cdk/cdk-release",
"tools/@aws-cdk/node-bundle",
"tools/@aws-cdk/pkglint",
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-cdk/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
## CLI Commands

All CDK CLI Commands are defined in `lib/config.ts`. This file is translated
into a valid `yargs` configuration by `bin/cli-args-gen`, which is generated by `@aws-cdk/cli-args-gen`.
into a valid `yargs` configuration by `bin/user-input-gen`, which is generated by `@aws-cdk/user-input-gen`.
The `yargs` configuration is generated into the function `parseCommandLineArguments()`,
in `lib/parse-command-line-arguments.ts`, and is checked into git for readability and
inspectability; do not edit this file by hand, as every subsequent `yarn build` will
overwrite any manual edits. If you need to leverage a `yargs` feature not used by
the CLI, you must add support for it to `@aws-cdk/cli-args-gen`.
the CLI, you must add support for it to `@aws-cdk/user-input-gen`.

Note that `bin/cli-args-gen` is executed by `ts-node`, which allows `config.ts` to
Note that `bin/user-input-gen` is executed by `ts-node`, which allows `config.ts` to
reference functions and other identifiers defined in the CLI before the CLI is
built.

### Dynamic Values

Some values, such as the user's platform, cannot be computed at build time.
Some commands depend on these values, and thus `cli-args-gen` must generate the
Some commands depend on these values, and thus `user-input-gen` must generate the
code to compute these values at build time.

The only way to do this today is to reference a parameter with `DynamicValue.fromParameter`.
Expand Down
9 changes: 6 additions & 3 deletions packages/aws-cdk/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { CliHelpers, type CliConfig } from '@aws-cdk/cli-args-gen';
import { CliHelpers, type CliConfig } from '@aws-cdk/user-input-gen';
import { StackActivityProgress } from './api/util/cloudformation/stack-activity-monitor';
import { MIGRATE_SUPPORTED_LANGUAGES } from './commands/migrate';
import { RequireApproval } from './diff';
Expand All @@ -8,8 +8,11 @@ import { availableInitLanguages } from './init';
export const YARGS_HELPERS = new CliHelpers('./util/yargs-helpers');

/**
* Source of truth for all CDK CLI commands. `cli-args-gen` translates this into the `yargs` definition
* in `lib/parse-command-line-arguments.ts`.
* Source of truth for all CDK CLI commands. `user-input-gen` translates this into:
*
* - the `yargs` definition in `lib/parse-command-line-arguments.ts`.
* - the `UserInput` type in `lib/user-input.ts`.
* - the `convertXxxToUserInput` functions in `lib/convert-to-user-input.ts`.
*/
export async function makeConfig(): Promise<CliConfig> {
return {
Expand Down
256 changes: 256 additions & 0 deletions packages/aws-cdk/lib/convert-to-user-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
// -------------------------------------------------------------------------------------------
// 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 { Command } from './settings';
import { UserInput, GlobalOptions } from './user-input';

// @ts-ignore TS6133
export function convertYargsToUserInput(args: any): UserInput {
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,
STACKS: args.STACKS,
};
break;

case 'synthesize':
commandOptions = {
exclusively: args.exclusively,
validation: args.validation,
quiet: args.quiet,
STACKS: args.STACKS,
};
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,
ENVIRONMENTS: args.ENVIRONMENTS,
};
break;

case 'gc':
commandOptions = {
action: args.action,
type: args.type,
rollbackBufferDays: args.rollbackBufferDays,
createdBufferDays: args.createdBufferDays,
confirm: args.confirm,
bootstrapStackName: args.bootstrapStackName,
ENVIRONMENTS: args.ENVIRONMENTS,
};
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,
importExistingResources: args.importExistingResources,
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,
STACKS: args.STACKS,
};
break;

case 'rollback':
commandOptions = {
all: args.all,
toolkitStackName: args.toolkitStackName,
force: args.force,
validateBootstrapVersion: args.validateBootstrapVersion,
orphan: args.orphan,
STACKS: args.STACKS,
};
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,
STACK: args.STACK,
};
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,
STACKS: args.STACKS,
};
break;

case 'destroy':
commandOptions = {
all: args.all,
exclusively: args.exclusively,
force: args.force,
STACKS: args.STACKS,
};
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,
STACKS: args.STACKS,
};
break;

case 'metadata':
commandOptions = {
STACK: args.STACK,
};
break;

case 'acknowledge':
commandOptions = {
ID: args.ID,
};
break;

case 'notices':
commandOptions = {
unacknowledged: args.unacknowledged,
};
break;

case 'init':
commandOptions = {
language: args.language,
list: args.list,
generateOnly: args.generateOnly,
TEMPLATE: args.TEMPLATE,
};
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 userInput: UserInput = {
_: args._[0],
globalOptions,
[args._[0]]: commandOptions,
};

return userInput;
}
Loading
Loading