Skip to content

Commit dc1647e

Browse files
authored
chore(cli): CliArguments interface generated from config.ts (#32556)
This PR: - generates a new type, `CliArguments` which is an interface created from the cli source-of-truth in `config.ts`. - renames `yargs-gen` into `cli-args-gen` to better reflect what we are generating now The purpose of `CliArguments` is to eventually replace our current `Arguments` type, turning it into a strongly-typed object. `Arguments` today looks like this: ```ts export type Arguments = { readonly _: [Command, ...string[]]; readonly exclusively?: boolean; readonly STACKS?: string[]; readonly lookups?: boolean; readonly [name: string]: unknown; }; ``` And because the last line in the definition essentially accepts any kind of property, we end up passing in and using values that are not documented anywhere. The purpose of this PR is to introduce a better type to enforce that the `args` object in `cli.ts` only holds values we expect. We are not currently using the new type anywhere; that will be done in a subsequent PR. The success criteria of this PR is that we are generating a new type from the source of truth that will eventually represent the type of the object we receive from CLI inputs. Part of #32474 ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d5e45c4 commit dc1647e

27 files changed

+1521
-23
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": "yargs-gen", "rootPath": "tools/@aws-cdk/yargs-gen" }
34+
{ "name": "cli-args-gen", "rootPath": "tools/@aws-cdk/cli-args-gen" }
3535
]
3636
},
3737
"extensions": {

codecov.yml

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ component_management:
3030
name: packages/aws-cdk # display name that can change freely
3131
paths:
3232
- packages/aws-cdk/**
33+
34+
# https://docs.codecov.com/docs/ignoring-paths
35+
ignore:
36+
- packages/aws-cdk/lib/parse-command-line-arguments.ts # this file is generated and some lines cannot be tested

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/yargs-gen",
13+
"tools/@aws-cdk/cli-args-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/yargs-gen",
80+
"tools/@aws-cdk/cli-args-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/yargs-gen`, which is generated by `@aws-cdk/yargs-gen`.
4+
into a valid `yargs` configuration by `bin/cli-args-gen`, which is generated by `@aws-cdk/cli-args-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/yargs-gen`.
9+
the CLI, you must add support for it to `@aws-cdk/cli-args-gen`.
1010

11-
Note that `bin/yargs-gen` is executed by `ts-node`, which allows `config.ts` to
11+
Note that `bin/cli-args-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 `yargs-gen` must generate the
18+
Some commands depend on these values, and thus `cli-args-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`.

0 commit comments

Comments
 (0)