-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(cli): function to turn yargs output to cliArguments #32696
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
de4838f
chore(cli): update Command enum
kaizencc 919c6d9
chore(cli): function to turn yargs output to cliArguments
kaizencc db0e89c
Merge branch 'main' into conroy/commandenum
kaizencc a1bbfbf
Merge branch 'main' into conroy/commandenum
kaizencc bc6ddfd
generate convert func in new file
kaizencc d606b17
add test
kaizencc 7f97067
Merge branch 'main' into conroy/commandenum
kaizencc 795bf08
update codecov to exclude generated files
kaizencc 1510105
test uses parseCommandLineArguments
kaizencc 3002617
Merge branch 'main' into conroy/commandenum
kaizencc a8b4187
Merge branch 'conroy/commandenum' of https://github.com/aws/aws-cdk i…
kaizencc ce2b2e5
use codecov ignore file
kaizencc be39bd3
fix tests
kaizencc 7c310b2
jest ignore files
kaizencc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
// ------------------------------------------------------------------------------------------- | ||
// GENERATED FROM packages/aws-cdk/lib/config.ts. | ||
// Do not edit by hand; all changes will be overwritten at build time from the config file. | ||
// ------------------------------------------------------------------------------------------- | ||
/* eslint-disable @stylistic/max-len */ | ||
import { CliArguments, GlobalOptions } from './cli-arguments'; | ||
import { Command } from './settings'; | ||
|
||
// @ts-ignore TS6133 | ||
export function convertToCliArgs(args: any): CliArguments { | ||
const globalOptions: GlobalOptions = { | ||
app: args.app, | ||
build: args.build, | ||
context: args.context, | ||
plugin: args.plugin, | ||
trace: args.trace, | ||
strict: args.strict, | ||
lookups: args.lookups, | ||
ignoreErrors: args.ignoreErrors, | ||
json: args.json, | ||
verbose: args.verbose, | ||
debug: args.debug, | ||
profile: args.profile, | ||
proxy: args.proxy, | ||
caBundlePath: args.caBundlePath, | ||
ec2creds: args.ec2creds, | ||
versionReporting: args.versionReporting, | ||
pathMetadata: args.pathMetadata, | ||
assetMetadata: args.assetMetadata, | ||
roleArn: args.roleArn, | ||
staging: args.staging, | ||
output: args.output, | ||
notices: args.notices, | ||
noColor: args.noColor, | ||
ci: args.ci, | ||
unstable: args.unstable, | ||
}; | ||
let commandOptions; | ||
switch (args._[0] as Command) { | ||
case 'list': | ||
commandOptions = { | ||
long: args.long, | ||
showDependencies: args.showDependencies, | ||
}; | ||
break; | ||
|
||
case 'synthesize': | ||
commandOptions = { | ||
exclusively: args.exclusively, | ||
validation: args.validation, | ||
quiet: args.quiet, | ||
}; | ||
break; | ||
|
||
case 'bootstrap': | ||
commandOptions = { | ||
bootstrapBucketName: args.bootstrapBucketName, | ||
bootstrapKmsKeyId: args.bootstrapKmsKeyId, | ||
examplePermissionsBoundary: args.examplePermissionsBoundary, | ||
customPermissionsBoundary: args.customPermissionsBoundary, | ||
bootstrapCustomerKey: args.bootstrapCustomerKey, | ||
qualifier: args.qualifier, | ||
publicAccessBlockConfiguration: args.publicAccessBlockConfiguration, | ||
tags: args.tags, | ||
execute: args.execute, | ||
trust: args.trust, | ||
trustForLookup: args.trustForLookup, | ||
cloudformationExecutionPolicies: args.cloudformationExecutionPolicies, | ||
force: args.force, | ||
terminationProtection: args.terminationProtection, | ||
showTemplate: args.showTemplate, | ||
toolkitStackName: args.toolkitStackName, | ||
template: args.template, | ||
previousParameters: args.previousParameters, | ||
}; | ||
break; | ||
|
||
case 'gc': | ||
commandOptions = { | ||
action: args.action, | ||
type: args.type, | ||
rollbackBufferDays: args.rollbackBufferDays, | ||
createdBufferDays: args.createdBufferDays, | ||
confirm: args.confirm, | ||
bootstrapStackName: args.bootstrapStackName, | ||
}; | ||
break; | ||
|
||
case 'deploy': | ||
commandOptions = { | ||
all: args.all, | ||
buildExclude: args.buildExclude, | ||
exclusively: args.exclusively, | ||
requireApproval: args.requireApproval, | ||
notificationArns: args.notificationArns, | ||
tags: args.tags, | ||
execute: args.execute, | ||
changeSetName: args.changeSetName, | ||
method: args.method, | ||
force: args.force, | ||
parameters: args.parameters, | ||
outputsFile: args.outputsFile, | ||
previousParameters: args.previousParameters, | ||
toolkitStackName: args.toolkitStackName, | ||
progress: args.progress, | ||
rollback: args.rollback, | ||
hotswap: args.hotswap, | ||
hotswapFallback: args.hotswapFallback, | ||
watch: args.watch, | ||
logs: args.logs, | ||
concurrency: args.concurrency, | ||
assetParallelism: args.assetParallelism, | ||
assetPrebuild: args.assetPrebuild, | ||
ignoreNoStacks: args.ignoreNoStacks, | ||
}; | ||
break; | ||
|
||
case 'rollback': | ||
commandOptions = { | ||
all: args.all, | ||
toolkitStackName: args.toolkitStackName, | ||
force: args.force, | ||
validateBootstrapVersion: args.validateBootstrapVersion, | ||
orphan: args.orphan, | ||
}; | ||
break; | ||
|
||
case 'import': | ||
commandOptions = { | ||
execute: args.execute, | ||
changeSetName: args.changeSetName, | ||
toolkitStackName: args.toolkitStackName, | ||
rollback: args.rollback, | ||
force: args.force, | ||
recordResourceMapping: args.recordResourceMapping, | ||
resourceMapping: args.resourceMapping, | ||
}; | ||
break; | ||
|
||
case 'watch': | ||
commandOptions = { | ||
buildExclude: args.buildExclude, | ||
exclusively: args.exclusively, | ||
changeSetName: args.changeSetName, | ||
force: args.force, | ||
toolkitStackName: args.toolkitStackName, | ||
progress: args.progress, | ||
rollback: args.rollback, | ||
hotswap: args.hotswap, | ||
hotswapFallback: args.hotswapFallback, | ||
logs: args.logs, | ||
concurrency: args.concurrency, | ||
}; | ||
break; | ||
|
||
case 'destroy': | ||
commandOptions = { | ||
all: args.all, | ||
exclusively: args.exclusively, | ||
force: args.force, | ||
}; | ||
break; | ||
|
||
case 'diff': | ||
commandOptions = { | ||
exclusively: args.exclusively, | ||
contextLines: args.contextLines, | ||
template: args.template, | ||
strict: args.strict, | ||
securityOnly: args.securityOnly, | ||
fail: args.fail, | ||
processed: args.processed, | ||
quiet: args.quiet, | ||
changeSet: args.changeSet, | ||
}; | ||
break; | ||
|
||
case 'metadata': | ||
commandOptions = {}; | ||
break; | ||
|
||
case 'acknowledge': | ||
commandOptions = {}; | ||
break; | ||
|
||
case 'notices': | ||
commandOptions = { | ||
unacknowledged: args.unacknowledged, | ||
}; | ||
break; | ||
|
||
case 'init': | ||
commandOptions = { | ||
language: args.language, | ||
list: args.list, | ||
generateOnly: args.generateOnly, | ||
}; | ||
break; | ||
|
||
case 'migrate': | ||
commandOptions = { | ||
stackName: args.stackName, | ||
language: args.language, | ||
account: args.account, | ||
region: args.region, | ||
fromPath: args.fromPath, | ||
fromStack: args.fromStack, | ||
outputPath: args.outputPath, | ||
fromScan: args.fromScan, | ||
filter: args.filter, | ||
compress: args.compress, | ||
}; | ||
break; | ||
|
||
case 'context': | ||
commandOptions = { | ||
reset: args.reset, | ||
force: args.force, | ||
clear: args.clear, | ||
}; | ||
break; | ||
|
||
case 'docs': | ||
commandOptions = { | ||
browser: args.browser, | ||
}; | ||
break; | ||
|
||
case 'doctor': | ||
commandOptions = {}; | ||
break; | ||
} | ||
const cliArguments: CliArguments = { | ||
_: args._, | ||
globalOptions, | ||
[args._[0]]: commandOptions, | ||
}; | ||
|
||
return cliArguments; | ||
} |
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,19 +1,106 @@ | ||
import { CliArguments } from '../lib/cli-arguments'; | ||
import { Command } from '../lib/settings'; | ||
import { convertToCliArgs } from '../lib/convert-to-cli-args'; | ||
|
||
// CliArguments is not being used right now, so the testing suite is rather redundant. | ||
// This file is meant to be populated when CliArguments is used. | ||
test('cli arguments can be used as a type', async () => { | ||
const argv: CliArguments = { | ||
_: [Command.DEPLOY], | ||
test('yargs object can be converted to cli arguments', async () => { | ||
// This input represents what would come out of yargs, i.e. | ||
// await parseCommandLineArguments(args); | ||
const input = { | ||
kaizencc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'_': ['deploy'], | ||
'notification-arns': ['[]'], | ||
'notificationArns': ['[]'], | ||
'v': 1, | ||
'verbose': 1, | ||
'lookups': true, | ||
'ignore-errors': false, | ||
'ignoreErrors': false, | ||
'json': false, | ||
'j': false, | ||
'debug': false, | ||
'ec2creds': undefined, | ||
'i': undefined, | ||
'version-reporting': undefined, | ||
'versionReporting': undefined, | ||
'path-metadata': undefined, | ||
'pathMetadata': undefined, | ||
'asset-metadata': undefined, | ||
'assetMetadata': undefined, | ||
'role-arn': undefined, | ||
'r': undefined, | ||
'roleArn': undefined, | ||
'staging': true, | ||
'no-color': false, | ||
'noColor': false, | ||
'ci': false, | ||
'unstable': [], | ||
'all': false, | ||
'build-exclude': [], | ||
'E': [], | ||
'buildExclude': [], | ||
'force': false, | ||
'f': false, | ||
'parameters': [{}], | ||
'previous-parameters': true, | ||
'previousParameters': true, | ||
'logs': true, | ||
'concurrency': 1, | ||
'asset-prebuild': true, | ||
'assetPrebuild': true, | ||
'ignore-no-stacks': false, | ||
'ignoreNoStacks': false, | ||
}; | ||
|
||
const result = convertToCliArgs(input); | ||
|
||
expect(result).toEqual({ | ||
_: ['deploy'], | ||
globalOptions: { | ||
lookups: true, | ||
app: undefined, | ||
assetMetadata: undefined, | ||
build: undefined, | ||
caBundlePath: undefined, | ||
context: undefined, | ||
ignoreErrors: false, | ||
noColor: false, | ||
pathMetadata: undefined, | ||
proxy: undefined, | ||
roleArn: undefined, | ||
staging: true, | ||
strict: undefined, | ||
verbose: 1, | ||
versionReporting: undefined, | ||
ci: false, | ||
debug: false, | ||
ec2creds: undefined, | ||
json: false, | ||
verbose: false, | ||
lookups: true, | ||
unstable: [], | ||
notices: undefined, | ||
output: undefined, | ||
}, | ||
}; | ||
|
||
expect(argv._[0]).toBe('deploy'); | ||
expect(argv.globalOptions?.lookups).toBeTruthy(); | ||
deploy: { | ||
all: false, | ||
assetParallelism: undefined, | ||
assetPrebuild: true, | ||
buildExclude: [], | ||
changeSetName: undefined, | ||
concurrency: 1, | ||
execute: undefined, | ||
exclusively: undefined, | ||
force: false, | ||
hotswap: undefined, | ||
hotswapFallback: undefined, | ||
ignoreNoStacks: false, | ||
logs: true, | ||
method: undefined, | ||
notificationArns: ['[]'], | ||
outputsFile: undefined, | ||
parameters: [{}], | ||
previousParameters: true, | ||
progress: undefined, | ||
requireApproval: undefined, | ||
rollback: undefined, | ||
tags: undefined, | ||
toolkitStackName: undefined, | ||
watch: undefined, | ||
}, | ||
}); | ||
}); |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at our current for this command I see:
aws-cdk/packages/aws-cdk/lib/cli.ts
Lines 433 to 434 in fcf4ecd
Should this PR also handle positional arguments? I would expect we have a strongly typed
args.acknowledge.id
or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. A big part of my refactor is to make sure we don't have to use
args
,argv
, andconfiguration.settings
everywhere and instead just have 1 object with arguments.Currently those positional arguments are found in index 1 and beyond on
argv._
:argv._: [Command, ...string]
It will be a bit awkward to figure out the right way to deal with that, which I would like to do in a separate PR.