Skip to content

Commit a8ad62c

Browse files
authored
chore(cli): rename cli-args-gen into user-input-gen (#32821)
This PR does not change CLI functionality because we are not using `CliArguments` yet. This PR includes the following related changes: - `CliArguments` are renamed `UserInput` to reflect what the schema represents -- they are options available to be specified via CLI options or `cdk.json`. - the tool previously known as `cli-arg-gen` is now named `user-input-gen` to reflect this change. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent aff160b commit a8ad62c

33 files changed

+106
-103
lines changed

aws-cdk.code-workspace

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"name": "aws-custom-resource-sdk-adapter",
3232
"rootPath": "packages/@aws-cdk/aws-custom-resource-sdk-adapter"
3333
},
34-
{ "name": "cli-args-gen", "rootPath": "tools/@aws-cdk/cli-args-gen" }
34+
{ "name": "user-input-gen", "rootPath": "tools/@aws-cdk/user-input-gen" }
3535
]
3636
},
3737
"extensions": {

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"packages/@aws-cdk-testing/*",
1111
"packages/@aws-cdk/*/lambda-packages/*",
1212
"tools/@aws-cdk/cdk-build-tools",
13-
"tools/@aws-cdk/cli-args-gen",
13+
"tools/@aws-cdk/user-input-gen",
1414
"tools/@aws-cdk/cdk-release",
1515
"tools/@aws-cdk/node-bundle",
1616
"tools/@aws-cdk/pkglint",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"packages/@aws-cdk-testing/*",
7878
"packages/@aws-cdk/*/lambda-packages/*",
7979
"tools/@aws-cdk/cdk-build-tools",
80-
"tools/@aws-cdk/cli-args-gen",
80+
"tools/@aws-cdk/user-input-gen",
8181
"tools/@aws-cdk/cdk-release",
8282
"tools/@aws-cdk/node-bundle",
8383
"tools/@aws-cdk/pkglint",

packages/aws-cdk/CONTRIBUTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
## CLI Commands
22

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

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

1515
### Dynamic Values
1616

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

2121
The only way to do this today is to reference a parameter with `DynamicValue.fromParameter`.

packages/aws-cdk/jest.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const config = {
1919
"<rootDir>/lib/api/aws-auth/sdk.ts",
2020
// Files generated by cli-args-gen
2121
"<rootDir>/lib/parse-command-line-arguments.ts",
22-
"<rootDir>/lib/cli-arguments.ts",
23-
"<rootDir>/lib/convert-to-cli-args.ts",
22+
"<rootDir>/lib/user-input.ts",
23+
"<rootDir>/lib/convert-to-user-input.ts",
2424
],
2525

2626
// We have many tests here that commonly time out

packages/aws-cdk/lib/config.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
2-
import { CliHelpers, type CliConfig } from '@aws-cdk/cli-args-gen';
2+
import { CliHelpers, type CliConfig } from '@aws-cdk/user-input-gen';
33
import { StackActivityProgress } from './api/util/cloudformation/stack-activity-monitor';
44
import { MIGRATE_SUPPORTED_LANGUAGES } from './commands/migrate';
55
import { RequireApproval } from './diff';
@@ -8,8 +8,11 @@ import { availableInitLanguages } from './init';
88
export const YARGS_HELPERS = new CliHelpers('./util/yargs-helpers');
99

1010
/**
11-
* Source of truth for all CDK CLI commands. `cli-args-gen` translates this into the `yargs` definition
12-
* in `lib/parse-command-line-arguments.ts`.
11+
* Source of truth for all CDK CLI commands. `user-input-gen` translates this into:
12+
*
13+
* - the `yargs` definition in `lib/parse-command-line-arguments.ts`.
14+
* - the `UserInput` type in `lib/user-input.ts`.
15+
* - the `convertXxxToUserInput` functions in `lib/convert-to-user-input.ts`.
1316
*/
1417
export async function makeConfig(): Promise<CliConfig> {
1518
return {

packages/aws-cdk/lib/convert-to-cli-args.ts renamed to packages/aws-cdk/lib/convert-to-user-input.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// Do not edit by hand; all changes will be overwritten at build time from the config file.
44
// -------------------------------------------------------------------------------------------
55
/* eslint-disable @stylistic/max-len */
6-
import { CliArguments, GlobalOptions } from './cli-arguments';
76
import { Command } from './settings';
7+
import { UserInput, GlobalOptions } from './user-input';
88

99
// @ts-ignore TS6133
10-
export function convertYargsToCliArgs(args: any): CliArguments {
10+
export function convertYargsToUserInput(args: any): UserInput {
1111
const globalOptions: GlobalOptions = {
1212
app: args.app,
1313
build: args.build,
@@ -250,17 +250,17 @@ export function convertYargsToCliArgs(args: any): CliArguments {
250250
commandOptions = {};
251251
break;
252252
}
253-
const cliArguments: CliArguments = {
253+
const userInput: UserInput = {
254254
_: args._[0],
255255
globalOptions,
256256
[args._[0]]: commandOptions,
257257
};
258258

259-
return cliArguments;
259+
return userInput;
260260
}
261261

262262
// @ts-ignore TS6133
263-
export function convertConfigToCliArgs(config: any): CliArguments {
263+
export function convertConfigToUserInput(config: any): UserInput {
264264
const globalOptions: GlobalOptions = {
265265
app: config.app,
266266
build: config.build,
@@ -428,7 +428,7 @@ export function convertConfigToCliArgs(config: any): CliArguments {
428428
browser: config.docs?.browser,
429429
};
430430
const doctorOptions = {};
431-
const cliArguments: CliArguments = {
431+
const userInput: UserInput = {
432432
globalOptions,
433433
list: listOptions,
434434
synthesize: synthesizeOptions,
@@ -450,5 +450,5 @@ export function convertConfigToCliArgs(config: any): CliArguments {
450450
doctor: doctorOptions,
451451
};
452452

453-
return cliArguments;
453+
return userInput;
454454
}

packages/aws-cdk/lib/cli-arguments.ts renamed to packages/aws-cdk/lib/user-input.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import { Command } from './settings';
77

88
/**
9-
* The structure of the CLI configuration, generated from packages/aws-cdk/lib/config.ts
9+
* The structure of the user input -- either CLI options or cdk.json -- generated from packages/aws-cdk/lib/config.ts
1010
*
1111
* @struct
1212
*/
13-
export interface CliArguments {
13+
export interface UserInput {
1414
/**
1515
* The CLI command name
1616
*/

packages/aws-cdk/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"scripts": {
99
"build": "cdk-build",
10-
"cli-args-gen": "ts-node --preferTsExts scripts/cli-args-gen.ts",
10+
"user-input-gen": "ts-node --preferTsExts scripts/user-input-gen.ts",
1111
"watch": "cdk-watch",
1212
"lint": "cdk-lint",
1313
"pkglint": "pkglint -f",
@@ -29,7 +29,7 @@
2929
},
3030
"cdk-build": {
3131
"pre": [
32-
"yarn cli-args-gen"
32+
"yarn user-input-gen"
3333
],
3434
"post": [
3535
"cp ../../node_modules/cdk-from-cfn/index_bg.wasm ./lib/",
@@ -70,7 +70,7 @@
7070
"@aws-cdk/cdk-build-tools": "0.0.0",
7171
"@aws-cdk/cli-plugin-contract": "0.0.0",
7272
"@aws-cdk/pkglint": "0.0.0",
73-
"@aws-cdk/cli-args-gen": "0.0.0",
73+
"@aws-cdk/user-input-gen": "0.0.0",
7474
"@octokit/rest": "^18.12.0",
7575
"@types/archiver": "^5.3.4",
7676
"@types/fs-extra": "^9.0.13",

packages/aws-cdk/scripts/cli-args-gen

-2
This file was deleted.

packages/aws-cdk/scripts/cli-args-gen.ts

-15
This file was deleted.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('./user-input-gen.js');
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as fs from 'fs';
2+
// eslint-disable-next-line import/no-extraneous-dependencies
3+
import { renderYargs, renderUserInputType, renderUserInputFuncs } from '@aws-cdk/user-input-gen';
4+
import { makeConfig, YARGS_HELPERS } from '../lib/config';
5+
6+
async function main() {
7+
const config = await makeConfig();
8+
fs.writeFileSync('./lib/parse-command-line-arguments.ts', await renderYargs(config, YARGS_HELPERS));
9+
fs.writeFileSync('./lib/user-input.ts', await renderUserInputType(config));
10+
fs.writeFileSync('./lib/convert-to-user-input.ts', await renderUserInputFuncs(config));
11+
}
12+
13+
main().then(() => {
14+
}).catch((e) => {
15+
throw e;
16+
});

packages/aws-cdk/test/cli-arguments.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { convertConfigToCliArgs, convertYargsToCliArgs } from '../lib/convert-to-cli-args';
1+
import { convertConfigToUserInput, convertYargsToUserInput } from '../lib/convert-to-user-input';
22
import { parseCommandLineArguments } from '../lib/parse-command-line-arguments';
33

44
describe('yargs', () => {
55
test('yargs object can be converted to cli arguments', async () => {
66
const input = await parseCommandLineArguments(['deploy', '-R', '-v', '--ci']);
77

8-
const result = convertYargsToCliArgs(input);
8+
const result = convertYargsToUserInput(input);
99

1010
expect(result).toEqual({
1111
_: 'deploy',
@@ -70,7 +70,7 @@ describe('yargs', () => {
7070
test('positional argument is correctly passed through -- variadic', async () => {
7171
const input = await parseCommandLineArguments(['deploy', 'stack1', 'stack2', '-R', '-v', '--ci']);
7272

73-
const result = convertYargsToCliArgs(input);
73+
const result = convertYargsToUserInput(input);
7474

7575
expect(result).toEqual({
7676
_: 'deploy',
@@ -84,7 +84,7 @@ describe('yargs', () => {
8484
test('positional argument is correctly passed through -- single', async () => {
8585
const input = await parseCommandLineArguments(['acknowledge', 'id1', '-v', '--ci']);
8686

87-
const result = convertYargsToCliArgs(input);
87+
const result = convertYargsToUserInput(input);
8888

8989
expect(result).toEqual({
9090
_: 'acknowledge',
@@ -109,7 +109,7 @@ describe('config', () => {
109109
},
110110
};
111111

112-
const result = convertConfigToCliArgs(input);
112+
const result = convertConfigToUserInput(input);
113113

114114
expect(result).toEqual({
115115
globalOptions: expect.objectContaining({

tools/@aws-cdk/cli-args-gen/lib/index.ts

-4
This file was deleted.

tools/@aws-cdk/cli-args-gen/README.md renamed to tools/@aws-cdk/user-input-gen/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# cli-args-gen
1+
# user-input-gen
22

33
Generates CDK CLI configurations from the source of truth in `packages/aws-cdk/lib/config.ts`.
44
Currently generates the following files:
55

66
- `packages/aws-cdk/lib/parse-command-line-arguments.ts`: `yargs` config.
7-
- `packages/aws-cdk-lib/cli-arguments.ts`: strongly typed `CliArguments` interface.
8-
- `packages/aws-cdk-lib/convert-to-cli-args.ts`: converts the `any` returned by `yargs` to `CliArguments`.
7+
- `packages/aws-cdk/lib/user-input.ts`: strongly typed `UserInput` interface.
8+
- `packages/aws-cdk/lib/convert-to-user-inpu.ts`: converts input from the CLI or `cdk.json` into `UserInput`.
99

1010
## Usage
1111

1212
```ts
13-
import { renderYargs } from '@aws-cdk/cli-args-gen';
13+
import { renderYargs } from '@aws-cdk/user-input-gen';
1414

1515
declare const config: CliConfig;
1616

tools/@aws-cdk/cli-args-gen/lib/cli-args-function-gen.ts renamed to tools/@aws-cdk/user-input-gen/lib/convert-to-user-input-gen.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,32 @@ import { CliAction, CliConfig } from './yargs-types';
77
const CLI_ARG_NAME = 'args';
88
const CONFIG_ARG_NAME = 'config';
99

10-
export async function renderCliArgsFunc(config: CliConfig): Promise<string> {
10+
export async function renderUserInputFuncs(config: CliConfig): Promise<string> {
1111
const scope = new Module('aws-cdk');
1212

1313
scope.documentation.push( '-------------------------------------------------------------------------------------------');
1414
scope.documentation.push('GENERATED FROM packages/aws-cdk/lib/config.ts.');
1515
scope.documentation.push('Do not edit by hand; all changes will be overwritten at build time from the config file.');
1616
scope.documentation.push('-------------------------------------------------------------------------------------------');
1717

18-
scope.addImport(new SelectiveModuleImport(scope, './cli-arguments', ['CliArguments', 'GlobalOptions']));
19-
const cliArgType = Type.fromName(scope, 'CliArguments');
20-
2118
scope.addImport(new SelectiveModuleImport(scope, './settings', ['Command']));
19+
scope.addImport(new SelectiveModuleImport(scope, './user-input', ['UserInput', 'GlobalOptions']));
20+
const userInputType = Type.fromName(scope, 'UserInput');
2221

23-
const createCliArguments = new FreeFunction(scope, {
24-
name: 'convertYargsToCliArgs',
22+
const convertYargsToUserInput = new FreeFunction(scope, {
23+
name: 'convertYargsToUserInput',
2524
export: true,
26-
returnType: cliArgType,
25+
returnType: userInputType,
2726
parameters: [
2827
{ name: 'args', type: Type.ANY },
2928
],
3029
});
31-
createCliArguments.addBody(code.expr.directCode(buildCliArgsFunction(config)));
30+
convertYargsToUserInput.addBody(code.expr.directCode(buildYargsToUserInputFunction(config)));
3231

3332
const createConfigArguments = new FreeFunction(scope, {
34-
name: 'convertConfigToCliArgs',
33+
name: 'convertConfigToUserInput',
3534
export: true,
36-
returnType: cliArgType,
35+
returnType: userInputType,
3736
parameters: [
3837
{ name: 'config', type: Type.ANY },
3938
],
@@ -52,14 +51,14 @@ export async function renderCliArgsFunc(config: CliConfig): Promise<string> {
5251
});
5352
}
5453

55-
function buildCliArgsFunction(config: CliConfig): string {
54+
function buildYargsToUserInputFunction(config: CliConfig): string {
5655
const globalOptions = buildGlobalOptions(config, CLI_ARG_NAME);
5756
const commandSwitch = buildCommandSwitch(config, CLI_ARG_NAME);
58-
const cliArgs = buildCliArgs(CLI_ARG_NAME);
57+
const userInput = buildUserInput(CLI_ARG_NAME);
5958
return [
6059
globalOptions,
6160
commandSwitch,
62-
cliArgs,
61+
userInput,
6362
].join('\n');
6463
}
6564

@@ -85,7 +84,7 @@ function buildGlobalOptions(config: CliConfig, argName: string): string {
8584
}
8685

8786
function buildCommandsList(config: CliConfig, argName: string): string {
88-
const commandOptions = [];
87+
const commandOptions: string[] = [];
8988
// Note: we are intentionally not including aliases for the default options that can be
9089
// specified via `cdk.json`. These options must be specified by the command name
9190
// i.e. acknowledge rather than ack.
@@ -140,27 +139,27 @@ function buildPositionalArguments(arg: { name: string; variadic: boolean }, argN
140139
return `${arg.name}: ${argName}.${arg.name}`;
141140
}
142141

143-
function buildCliArgs(argName: string): string {
142+
function buildUserInput(argName: string): string {
144143
return [
145-
'const cliArguments: CliArguments = {',
144+
'const userInput: UserInput = {',
146145
`_: ${argName}._[0],`,
147146
'globalOptions,',
148147
`[${argName}._[0]]: commandOptions`,
149148
'}',
150149
'',
151-
'return cliArguments',
150+
'return userInput',
152151
].join('\n');
153152
}
154153

155154
function buildConfigArgs(config: CliConfig): string {
156155
return [
157-
'const cliArguments: CliArguments = {',
156+
'const userInput: UserInput = {',
158157
'globalOptions,',
159158
...(Object.keys(config.commands).map((commandName) => {
160159
return `'${commandName}': ${kebabToCamelCase(commandName)}Options,`;
161160
})),
162161
'}',
163162
'',
164-
'return cliArguments',
163+
'return userInput',
165164
].join('\n');
166165
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './yargs-gen';
2+
export * from './yargs-types';
3+
export * from './user-input-gen';
4+
export * from './convert-to-user-input-gen';

0 commit comments

Comments
 (0)