Skip to content

Commit 0f6ce56

Browse files
authored
fix(toolkit): options requiring arguments fail if not supplied (#2197)
Some options require arguments, but without passing `requiresArg: true` to `yargs` it will happily accept the flag and put `undefined` or an empty string in the value (instead of rejecting the invocation). Add `requiresArg` to a number of options that have this property. Fixes #2192.
1 parent 17ba29a commit 0f6ce56

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: packages/aws-cdk/bin/cdk.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function parseCommandLineArguments() {
3333
return yargs
3434
.env('CDK')
3535
.usage('Usage: cdk -a <cdk-app> COMMAND')
36-
.option('app', { type: 'string', alias: 'a', desc: 'REQUIRED: Command-line for executing your CDK app (e.g. "node bin/my-app.js")' })
36+
.option('app', { type: 'string', alias: 'a', desc: 'REQUIRED: Command-line for executing your CDK app (e.g. "node bin/my-app.js")', requiresArg: true })
3737
.option('context', { type: 'array', alias: 'c', desc: 'Add contextual string parameter.', nargs: 1, requiresArg: 'KEY=VALUE' })
3838
.option('plugin', { type: 'array', alias: 'p', desc: 'Name or path of a node package that extend the CDK features. Can be specified multiple times', nargs: 1 })
3939
.option('rename', { type: 'string', desc: 'Rename stack name if different from the one defined in the cloud executable', requiresArg: '[ORIGINAL:]RENAMED' })
@@ -42,20 +42,20 @@ async function parseCommandLineArguments() {
4242
.option('ignore-errors', { type: 'boolean', default: false, desc: 'Ignores synthesis errors, which will likely produce an invalid output' })
4343
.option('json', { type: 'boolean', alias: 'j', desc: 'Use JSON output instead of YAML' })
4444
.option('verbose', { type: 'boolean', alias: 'v', desc: 'Show debug logs' })
45-
.option('profile', { type: 'string', desc: 'Use the indicated AWS profile as the default environment' })
46-
.option('proxy', { type: 'string', desc: 'Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified.' })
45+
.option('profile', { type: 'string', desc: 'Use the indicated AWS profile as the default environment', requiresArg: true })
46+
.option('proxy', { type: 'string', desc: 'Use the indicated proxy. Will read from HTTPS_PROXY environment variable if not specified.', requiresArg: true })
4747
.option('ec2creds', { type: 'boolean', alias: 'i', default: undefined, desc: 'Force trying to fetch EC2 instance credentials. Default: guess EC2 instance status.' })
4848
.option('version-reporting', { type: 'boolean', desc: 'Include the "AWS::CDK::Metadata" resource in synthesized templates (enabled by default)', default: undefined })
4949
.option('path-metadata', { type: 'boolean', desc: 'Include "aws:cdk:path" CloudFormation metadata for each resource (enabled by default)', default: true })
5050
.option('asset-metadata', { type: 'boolean', desc: 'Include "aws:asset:*" CloudFormation metadata for resources that user assets (enabled by default)', default: true })
51-
.option('role-arn', { type: 'string', alias: 'r', desc: 'ARN of Role to use when invoking CloudFormation', default: undefined })
52-
.option('toolkit-stack-name', { type: 'string', desc: 'The name of the CDK toolkit stack' })
51+
.option('role-arn', { type: 'string', alias: 'r', desc: 'ARN of Role to use when invoking CloudFormation', default: undefined, requiresArg: true })
52+
.option('toolkit-stack-name', { type: 'string', desc: 'The name of the CDK toolkit stack', requiresArg: true })
5353
.command([ 'list', 'ls' ], 'Lists all stacks in the app', yargs => yargs
5454
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'display environment information for each stack' }))
5555
.command([ 'synthesize [STACKS..]', 'synth [STACKS..]' ], 'Synthesizes and prints the CloudFormation template for this stack', yargs => yargs
5656
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' })
5757
.option('interactive', { type: 'boolean', alias: 'i', desc: 'interactively watch and show template updates' })
58-
.option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory' })
58+
.option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory', requiresArg: true })
5959
.option('numbered', { type: 'boolean', alias: 'n', desc: 'prefix filenames with numbers to indicate deployment ordering' }))
6060
.command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment')
6161
.command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs
@@ -68,8 +68,8 @@ async function parseCommandLineArguments() {
6868
.option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }))
6969
.command('diff [STACKS..]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs
7070
.option('exclusively', { type: 'boolean', alias: 'e', desc: 'only diff requested stacks, don\'t include dependencies' })
71-
.option('context-lines', { type: 'number', desc: 'number of context lines to include in arbitrary JSON diff rendering', default: 3 })
72-
.option('template', { type: 'string', desc: 'the path to the CloudFormation template to compare with' })
71+
.option('context-lines', { type: 'number', desc: 'number of context lines to include in arbitrary JSON diff rendering', default: 3, requiresArg: true })
72+
.option('template', { type: 'string', desc: 'the path to the CloudFormation template to compare with', requiresArg: true })
7373
.option('strict', { type: 'boolean', desc: 'do not filter out AWS::CDK::Metadata resources', default: false }))
7474
.command('metadata [STACK]', 'Returns all metadata associated with this stack')
7575
.command('init [TEMPLATE]', 'Create a new, empty CDK project from a template. Invoked without TEMPLATE, the app template will be used.', yargs => yargs

0 commit comments

Comments
 (0)