You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(cli): simplify config with helper functions (#32547)
### Reason for this change
Simplify the codegen for CLI config. Previously the generated function expected a number of arguments at call time.
Instead we now require a single helpers object at build time. This holds typewriter references to any function called during config parsing.
Additionally, some the helper functions for init and migrate are now just called at build time. This is fine because these values don't change dynamically unless a code change is made to the CLI.
### Description of changes
- Moved all helper functions into a single file
- Created a typewriter proxy class for that file
- Use the module proxy instead passing arguments at runtime
- This allows us to get rid of the `DynamicValue` stuff all-together and instead we can just check if a value is a typewriter expression.
### Description of how you validated changes
Existing tests cover this. Run additional manual verification as well.
### 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*
'app': {type: 'string',alias: 'a',desc: 'REQUIRED WHEN RUNNING APP: command-line for executing your app or a cloud assembly directory (e.g. "node bin/my-app.js"). Can also be specified in cdk.json or ~/.cdk.json',requiresArg: true},
@@ -34,11 +37,11 @@ export function makeConfig(): CliConfig {
34
37
'output': {type: 'string',alias: 'o',desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)',requiresArg: true},
'no-color': {type: 'boolean',desc: 'Removes colors and other style from console output',default: false},
37
-
'ci': {type: 'boolean',desc: 'Force CI detection. If CI=true then logs will be sent to stdout instead of stderr',default: DynamicValue.fromInline(()=>process.env.CI!==undefined)},
40
+
'ci': {type: 'boolean',desc: 'Force CI detection. If CI=true then logs will be sent to stdout instead of stderr',default: YARGS_HELPERS.isCI()},
38
41
'unstable': {type: 'array',desc: '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: []},
39
42
},
40
43
commands: {
41
-
'list': {
44
+
list: {
42
45
arg: {
43
46
name: 'STACKS',
44
47
variadic: true,
@@ -50,17 +53,17 @@ export function makeConfig(): CliConfig {
50
53
'show-dependencies': {type: 'boolean',default: false,alias: 'd',desc: 'Display stack dependency information for each stack'},
51
54
},
52
55
},
53
-
'synthesize': {
56
+
synthesize: {
54
57
arg: {
55
58
name: 'STACKS',
56
59
variadic: true,
57
60
},
58
61
aliases: ['synth'],
59
62
description: 'Synthesizes and prints the CloudFormation template for this stack',
'validation': {type: 'boolean',desc: 'After synthesis, validate stacks with the "validateOnSynth" attribute set (can also be controlled with CDK_VALIDATION)',default: true},
63
-
'quiet': {type: 'boolean',alias: 'q',desc: 'Do not output CloudFormation Template to stdout',default: false},
validation: {type: 'boolean',desc: 'After synthesis, validate stacks with the "validateOnSynth" attribute set (can also be controlled with CDK_VALIDATION)',default: true},
66
+
quiet: {type: 'boolean',alias: 'q',desc: 'Do not output CloudFormation Template to stdout',default: false},
64
67
},
65
68
},
66
69
bootstrap: {
@@ -242,18 +245,6 @@ export function makeConfig(): CliConfig {
242
245
variadic: true,
243
246
},
244
247
options: {
245
-
// I'm fairly certain none of these options, present for 'deploy', make sense for 'watch':
246
-
// .option('all', { type: 'boolean', default: false, desc: 'Deploy all available stacks' })
// .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {}})
254
-
// .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' })
255
-
// .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true })
256
-
// .option('notification-arns', { type: 'array', desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events', nargs: 1, requiresArg: true })
257
248
'build-exclude': {type: 'array',alias: 'E',desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',default: []},
force: {type: 'boolean',alias: 'f',desc: 'Do not ask for confirmation before destroying the stacks'},
301
292
},
302
293
},
303
294
diff: {
@@ -336,7 +327,7 @@ export function makeConfig(): CliConfig {
336
327
notices: {
337
328
description: 'Returns a list of relevant notices',
338
329
options: {
339
-
'unacknowledged': {type: 'boolean',alias: 'u',default: false,desc: 'Returns a list of unacknowledged notices'},
330
+
unacknowledged: {type: 'boolean',alias: 'u',default: false,desc: 'Returns a list of unacknowledged notices'},
340
331
},
341
332
},
342
333
init: {
@@ -346,16 +337,16 @@ export function makeConfig(): CliConfig {
346
337
variadic: false,
347
338
},
348
339
options: {
349
-
'language': {type: 'string',alias: 'l',desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)',choices: DynamicValue.fromParameter('availableInitLanguages')}asany,// TODO: preamble, this initTemplateLanguages variable needs to go as a statement there.
340
+
'language': {type: 'string',alias: 'l',desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)',choices: awaitavailableInitLanguages()},
350
341
'list': {type: 'boolean',desc: 'List the available templates'},
351
342
'generate-only': {type: 'boolean',default: false,desc: 'If true, only generates project files, without executing additional operations such as setting up a git repo, installing dependencies or compiling the project'},
352
343
},
353
344
},
354
-
'migrate': {
345
+
migrate: {
355
346
description: falseasany,
356
347
options: {
357
348
'stack-name': {type: 'string',alias: 'n',desc: 'The name assigned to the stack created in the new project. The name of the app will be based off this name as well.',requiresArg: true},
358
-
'language': {type: 'string',default: 'typescript',alias: 'l',desc: 'The language to be used for the new project',choices: DynamicValue.fromParameter('migrateSupportedLanguages')asany},
349
+
'language': {type: 'string',default: 'typescript',alias: 'l',desc: 'The language to be used for the new project',choices: MIGRATE_SUPPORTED_LANGUAGES},
359
350
'account': {type: 'string',desc: 'The account to retrieve the CloudFormation stack template from'},
360
351
'region': {type: 'string',desc: 'The region to retrieve the CloudFormation stack template from'},
361
352
'from-path': {type: 'string',desc: 'The path to the CloudFormation template to migrate. Use this for locally stored templates'},
@@ -379,54 +370,29 @@ export function makeConfig(): CliConfig {
379
370
'compress': {type: 'boolean',desc: 'Use this flag to zip the generated CDK app'},
380
371
},
381
372
},
382
-
'context': {
373
+
context: {
383
374
description: 'Manage cached context values',
384
375
options: {
385
-
'reset': {alias: 'e',desc: 'The context key (or its index) to reset',type: 'string',requiresArg: true},
@@ -143,7 +137,7 @@ export function parseCommandLineArguments(
143
137
.option('ci',{
144
138
type: 'boolean',
145
139
desc: 'Force CI detection. If CI=true then logs will be sent to stdout instead of stderr',
146
-
default: process.env.CI!==undefined,
140
+
default: helpers.isCI(),
147
141
})
148
142
.option('unstable',{
149
143
type: 'array',
@@ -424,8 +418,8 @@ export function parseCommandLineArguments(
424
418
type: 'boolean',
425
419
desc: "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",
desc: "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",
@@ -570,8 +564,8 @@ export function parseCommandLineArguments(
570
564
type: 'boolean',
571
565
desc: "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",
desc: "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",
@@ -679,7 +673,7 @@ export function parseCommandLineArguments(
679
673
type: 'string',
680
674
alias: 'l',
681
675
desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)',
0 commit comments