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
fix(cli): cdk deploy -R does not disable rollback (#32514)
### Issue
`cdk deploy -R` should be the same as `cdk deploy --no-rollback` or `cdk deploy --rollback=false`, but has no effect
### Reason for this change
PR #31850 introduced this bug by accidentally flipping the order of arguments passed to the `yargsNegativeAlias` helper.
This caused the helper to have no effect.
### Description of changes
- Changed the codegen to fully generate negative aliases for the user
- Fixed the generate code to use the correct argument order again for `yargsNegativeAlias`
- Renamed the parameters to make it easier to understand.
- Made `nargs: 1` and `requiresArg: true` implied for all array options. Some options did miss one or both of these. This was an oversight.
### Description of how you validated changes
Added an explicit test case for `-R`.
### 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*
Copy file name to clipboardExpand all lines: packages/aws-cdk/lib/config.ts
+13-25
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,8 @@ export function makeConfig(): CliConfig {
13
13
globalOptions: {
14
14
'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},
15
15
'build': {type: 'string',desc: 'Command-line for a pre-synth build'},
'plugin': {type: 'array',alias: 'p',desc: 'Name or path of a node package that extend the CDK features. Can be specified multiple times'},
18
18
'trace': {type: 'boolean',desc: 'Print trace for stack warnings'},
19
19
'strict': {type: 'boolean',desc: 'Do not construct stacks with warnings'},
20
20
'lookups': {type: 'boolean',desc: 'Perform context lookups (synthesis fails if this is disabled and context lookups need to be performed)',default: true},
@@ -77,11 +77,11 @@ export function makeConfig(): CliConfig {
77
77
'bootstrap-customer-key': {type: 'boolean',desc: 'Create a Customer Master Key (CMK) for the bootstrap bucket (you will be charged but can customize permissions, modern bootstrapping only)',default: undefined,conflicts: 'bootstrap-kms-key-id'},
78
78
'qualifier': {type: 'string',desc: 'String which must be unique for each bootstrap stack. You must configure it on your CDK app if you change this from the default.',default: undefined},
79
79
'public-access-block-configuration': {type: 'boolean',desc: 'Block public access configuration on CDK toolkit bucket (enabled by default) ',default: undefined},
80
-
'tags': {type: 'array',alias: 't',desc: 'Tags to add for the stack (KEY=VALUE)',nargs: 1,requiresArg: true,default: []},
80
+
'tags': {type: 'array',alias: 't',desc: 'Tags to add for the stack (KEY=VALUE)',default: []},
81
81
'execute': {type: 'boolean',desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet)',default: true},
82
-
'trust': {type: 'array',desc: 'The AWS account IDs that should be trusted to perform deployments into this environment (may be repeated, modern bootstrapping only)',default: [],nargs: 1,requiresArg: true},
83
-
'trust-for-lookup': {type: 'array',desc: 'The AWS account IDs that should be trusted to look up values in this environment (may be repeated, modern bootstrapping only)',default: [],nargs: 1,requiresArg: true},
84
-
'cloudformation-execution-policies': {type: 'array',desc: 'The Managed Policy ARNs that should be attached to the role performing deployments into this environment (may be repeated, modern bootstrapping only)',default: [],nargs: 1,requiresArg: true},
82
+
'trust': {type: 'array',desc: 'The AWS account IDs that should be trusted to perform deployments into this environment (may be repeated, modern bootstrapping only)',default: []},
83
+
'trust-for-lookup': {type: 'array',desc: 'The AWS account IDs that should be trusted to look up values in this environment (may be repeated, modern bootstrapping only)',default: []},
84
+
'cloudformation-execution-policies': {type: 'array',desc: 'The Managed Policy ARNs that should be attached to the role performing deployments into this environment (may be repeated, modern bootstrapping only)',default: []},
85
85
'force': {alias: 'f',type: 'boolean',desc: 'Always bootstrap even if it would downgrade template version',default: false},
86
86
'termination-protection': {type: 'boolean',default: undefined,desc: 'Toggle CloudFormation termination protection on the bootstrap stacks'},
87
87
'show-template': {type: 'boolean',desc: 'Instead of actual bootstrapping, print the current CLI\'s bootstrapping template to stdout for customization',default: false},
@@ -109,12 +109,12 @@ export function makeConfig(): CliConfig {
109
109
description: 'Deploys the stack(s) named STACKS into your AWS account',
110
110
options: {
111
111
'all': {type: 'boolean',desc: 'Deploy all available stacks',default: false},
112
-
'build-exclude': {type: 'array',alias: 'E',nargs: 1,desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',default: []},
112
+
'build-exclude': {type: 'array',alias: 'E',desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',default: []},
'require-approval': {type: 'string',choices: [RequireApproval.Never,RequireApproval.AnyChange,RequireApproval.Broadening],desc: 'What security-sensitive changes need manual approval'},
115
-
'notification-arns': {type: 'array',desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events. These will be added to ARNs specified with the \'notificationArns\' stack property.',nargs: 1,requiresArg: true},
115
+
'notification-arns': {type: 'array',desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events. These will be added to ARNs specified with the \'notificationArns\' stack property.'},
116
116
// @deprecated(v2) -- tags are part of the Cloud Assembly and tags specified here will be overwritten on the next deployment
117
-
'tags': {type: 'array',alias: 't',desc: 'Tags to add to the stack (KEY=VALUE), overrides tags from Cloud Assembly (deprecated)',nargs: 1,requiresArg: true},
117
+
'tags': {type: 'array',alias: 't',desc: 'Tags to add to the stack (KEY=VALUE), overrides tags from Cloud Assembly (deprecated)'},
118
118
'execute': {type: 'boolean',desc: 'Whether to execute ChangeSet (--no-execute will NOT execute the ChangeSet) (deprecated)',deprecated: true},
119
119
'change-set-name': {type: 'string',desc: 'Name of the CloudFormation change set to create (only if method is not direct)'},
120
120
'method': {
@@ -125,7 +125,7 @@ export function makeConfig(): CliConfig {
125
125
desc: 'How to perform the deployment. Direct is a bit faster but lacks progress information',
126
126
},
127
127
'force': {alias: 'f',type: 'boolean',desc: 'Always deploy stack even if templates are identical',default: false},
128
-
'parameters': {type: 'array',desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)',nargs: 1,requiresArg: true,default: {}},
128
+
'parameters': {type: 'array',desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)',default: {}},
129
129
'outputs-file': {type: 'string',alias: 'O',desc: 'Path to file where stack outputs will be written as JSON',requiresArg: true},
130
130
'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)'},
131
131
'toolkit-stack-name': {type: 'string',desc: 'The name of the existing CDK toolkit stack (only used for app using legacy synthesis)',requiresArg: true},
@@ -136,11 +136,6 @@ export function makeConfig(): CliConfig {
136
136
'Note: do **not** disable this flag for deployments with resource replacements, as that will always fail',
137
137
negativeAlias: 'R',
138
138
},
139
-
'R': {
140
-
type: 'boolean',
141
-
hidden: true,
142
-
// Hack to get '-R' as an alias for '--no-rollback', suggested by: https://github.com/yargs/yargs/issues/1729
143
-
},
144
139
'hotswap': {
145
140
type: 'boolean',
146
141
desc: "Attempts to perform a 'hotswap' deployment, "+
@@ -199,8 +194,6 @@ export function makeConfig(): CliConfig {
199
194
'orphan': {
200
195
// alias: 'o' conflicts with --output
201
196
type: 'array',
202
-
nargs: 1,
203
-
requiresArg: true,
204
197
desc: 'Orphan the given resources, identified by their logical ID (can be specified multiple times)',
205
198
default: [],
206
199
},
@@ -261,7 +254,7 @@ export function makeConfig(): CliConfig {
261
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)' })
262
255
// .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true })
263
256
// .option('notification-arns', { type: 'array', desc: 'ARNs of SNS topics that CloudFormation will notify with stack related events', nargs: 1, requiresArg: true })
264
-
'build-exclude': {type: 'array',alias: 'E',nargs: 1,desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',default: []},
257
+
'build-exclude': {type: 'array',alias: 'E',desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',default: []},
Copy file name to clipboardExpand all lines: packages/aws-cdk/lib/parse-command-line-arguments.ts
+17-16
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ export function parseCommandLineArguments(
39
39
alias: 'p',
40
40
desc: 'Name or path of a node package that extend the CDK features. Can be specified multiple times',
41
41
nargs: 1,
42
+
requiresArg: true,
42
43
})
43
44
.option('trace',{
44
45
type: 'boolean',
@@ -148,6 +149,8 @@ export function parseCommandLineArguments(
148
149
type: 'array',
149
150
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.',
150
151
default: [],
152
+
nargs: 1,
153
+
requiresArg: true,
151
154
})
152
155
.command(['list [STACKS..]','ls [STACKS..]'],'Lists all stacks in the app',(yargs: Argv)=>
153
156
yargs
@@ -231,9 +234,9 @@ export function parseCommandLineArguments(
231
234
type: 'array',
232
235
alias: 't',
233
236
desc: 'Tags to add for the stack (KEY=VALUE)',
237
+
default: [],
234
238
nargs: 1,
235
239
requiresArg: true,
236
-
default: [],
237
240
})
238
241
.option('execute',{
239
242
type: 'boolean',
@@ -339,9 +342,10 @@ export function parseCommandLineArguments(
339
342
.option('build-exclude',{
340
343
type: 'array',
341
344
alias: 'E',
342
-
nargs: 1,
343
345
desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',
344
346
default: [],
347
+
nargs: 1,
348
+
requiresArg: true,
345
349
})
346
350
.option('exclusively',{
347
351
type: 'boolean',
@@ -391,9 +395,9 @@ export function parseCommandLineArguments(
391
395
.option('parameters',{
392
396
type: 'array',
393
397
desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)',
398
+
default: {},
394
399
nargs: 1,
395
400
requiresArg: true,
396
-
default: {},
397
401
})
398
402
.option('outputs-file',{
399
403
type: 'string',
@@ -420,11 +424,8 @@ export function parseCommandLineArguments(
420
424
type: 'boolean',
421
425
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",
@@ -486,10 +487,10 @@ export function parseCommandLineArguments(
486
487
})
487
488
.option('orphan',{
488
489
type: 'array',
489
-
nargs: 1,
490
-
requiresArg: true,
491
490
desc: 'Orphan the given resources, identified by their logical ID (can be specified multiple times)',
492
491
default: [],
492
+
nargs: 1,
493
+
requiresArg: true,
493
494
})
494
495
)
495
496
.command('import [STACK]','Import existing resource(s) into the given STACK',(yargs: Argv)=>
@@ -535,9 +536,10 @@ export function parseCommandLineArguments(
535
536
.option('build-exclude',{
536
537
type: 'array',
537
538
alias: 'E',
538
-
nargs: 1,
539
539
desc: 'Do not rebuild asset with the given ID. Can be specified multiple times',
540
540
default: [],
541
+
nargs: 1,
542
+
requiresArg: true,
541
543
})
542
544
.option('exclusively',{
543
545
type: 'boolean',
@@ -568,11 +570,8 @@ export function parseCommandLineArguments(
568
570
type: 'boolean',
569
571
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",
@@ -734,6 +733,8 @@ export function parseCommandLineArguments(
734
733
.option('filter',{
735
734
type: 'array',
736
735
desc: 'Filters the resource scan based on the provided criteria in the following format: "key1=value1,key2=value2"\n This field can be passed multiple times for OR style filtering: \n filtering options: \n resource-identifier: A key-value pair that identifies the target resource. i.e. {"ClusterName", "myCluster"}\n resource-type-prefix: A string that represents a type-name prefix. i.e. "AWS::DynamoDB::"\n tag-key: a string that matches resources with at least one tag with the provided key. i.e. "myTagKey"\n tag-value: a string that matches resources with at least one tag with the provided value. i.e. "myTagValue"',
0 commit comments