-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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*
- Loading branch information
Showing
10 changed files
with
167 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env node | ||
// source maps must be enabled before importing files | ||
process.setSourceMapsEnabled(true); | ||
const { cli } = require("../lib/cli"); | ||
const { cli } = require("../lib"); | ||
|
||
cli(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* yargs middleware to negate an option if a negative alias is provided | ||
* E.g. `-R` will imply `--rollback=false` | ||
* | ||
* @param optionToNegate The name of the option to negate, e.g. `rollback` | ||
* @param negativeAlias The alias that should negate the option, e.g. `R` | ||
* @returns | ||
*/ | ||
export function yargsNegativeAlias<T extends { [x in S | L]: boolean | undefined }, S extends string, L extends string>( | ||
negativeAlias: S, | ||
optionToNegate: L, | ||
): (argv: T) => T { | ||
return (argv: T) => { | ||
// if R in argv && argv[R] | ||
// then argv[rollback] = false | ||
if (negativeAlias in argv && argv[negativeAlias]) { | ||
(argv as any)[optionToNegate] = false; | ||
} | ||
return argv; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { parseCommandLineArguments } from '../lib/parse-command-line-arguments'; | ||
import { yargsNegativeAlias } from '../lib/util/yargs-helpers'; | ||
|
||
test('cdk deploy -R sets rollback to false', async () => { | ||
const argv = await parseCommandLineArguments(['deploy', '-R'], 'open', ['typescript'], ['typescript'], 'test', yargsNegativeAlias); | ||
|
||
expect(argv.rollback).toBe(false); | ||
}); |
Oops, something went wrong.