Skip to content

Commit b670ba8

Browse files
kaizenccmrgrain
andauthored
chore(cli): generate conversion from cdk.json to cli arguments (#32803)
This PR does not change the functionality of the CLI (yet) It does however articulate a schema for what `cdk.json` should look like in the future. I'm aware that we honor a slightly different set of rules in `cdk.json` that _is not documented anywhere_, and we will have to honor those rules ad-hoc. However, this will hopefully move us towards a strongly-typed future where `cdk.json` contents mirror CLI argument options. - global options are specified at the base level of `cdk.json` - command specific options will be prefixed by their command name. NOTE: some options are honored at the base level today. I will have to, in a separate PR, find each of these instances and take care of them but ensuring we still map them to the correct place in `CliArguments`. ```json { "app": "npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts", "output": "cdk.out", "build": "npx projen bundle", "watch": { "exclude": [ "README.md", "cdk*.json", "**/*.d.ts", "**/*.js", "tsconfig.json", "package*.json", "yarn.lock", "node_modules" ] } ``` This will turn into the following `CliArgument` object: ```ts { globalOptions: { app: 'npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts', output: 'cdk.out', build: 'npx projen bundle', watch: { exclude: [ "README.md", "cdk*.json", "**/*.d.ts", "**/*.js", "tsconfig.json", "package*.json", "yarn.lock", "node_modules", ], }, }; ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --------- Co-authored-by: Momo Kornher <[email protected]>
1 parent d6013a7 commit b670ba8

File tree

7 files changed

+420
-104
lines changed

7 files changed

+420
-104
lines changed

packages/aws-cdk/lib/cli-arguments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface CliArguments {
1414
/**
1515
* The CLI command name
1616
*/
17-
readonly _: Command;
17+
readonly _?: Command;
1818

1919
/**
2020
* Global options available to all CLI commands

packages/aws-cdk/lib/convert-to-cli-args.ts

+195-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CliArguments, GlobalOptions } from './cli-arguments';
77
import { Command } from './settings';
88

99
// @ts-ignore TS6133
10-
export function convertToCliArgs(args: any): CliArguments {
10+
export function convertYargsToCliArgs(args: any): CliArguments {
1111
const globalOptions: GlobalOptions = {
1212
app: args.app,
1313
build: args.build,
@@ -258,3 +258,197 @@ export function convertToCliArgs(args: any): CliArguments {
258258

259259
return cliArguments;
260260
}
261+
262+
// @ts-ignore TS6133
263+
export function convertConfigToCliArgs(config: any): CliArguments {
264+
const globalOptions: GlobalOptions = {
265+
app: config.app,
266+
build: config.build,
267+
context: config.context,
268+
plugin: config.plugin,
269+
trace: config.trace,
270+
strict: config.strict,
271+
lookups: config.lookups,
272+
ignoreErrors: config.ignoreErrors,
273+
json: config.json,
274+
verbose: config.verbose,
275+
debug: config.debug,
276+
profile: config.profile,
277+
proxy: config.proxy,
278+
caBundlePath: config.caBundlePath,
279+
ec2creds: config.ec2creds,
280+
versionReporting: config.versionReporting,
281+
pathMetadata: config.pathMetadata,
282+
assetMetadata: config.assetMetadata,
283+
roleArn: config.roleArn,
284+
staging: config.staging,
285+
output: config.output,
286+
notices: config.notices,
287+
noColor: config.noColor,
288+
ci: config.ci,
289+
unstable: config.unstable,
290+
};
291+
const listOptions = {
292+
long: config.list?.long,
293+
showDependencies: config.list?.showDependencies,
294+
};
295+
const synthesizeOptions = {
296+
exclusively: config.synthesize?.exclusively,
297+
validation: config.synthesize?.validation,
298+
quiet: config.synthesize?.quiet,
299+
};
300+
const bootstrapOptions = {
301+
bootstrapBucketName: config.bootstrap?.bootstrapBucketName,
302+
bootstrapKmsKeyId: config.bootstrap?.bootstrapKmsKeyId,
303+
examplePermissionsBoundary: config.bootstrap?.examplePermissionsBoundary,
304+
customPermissionsBoundary: config.bootstrap?.customPermissionsBoundary,
305+
bootstrapCustomerKey: config.bootstrap?.bootstrapCustomerKey,
306+
qualifier: config.bootstrap?.qualifier,
307+
publicAccessBlockConfiguration: config.bootstrap?.publicAccessBlockConfiguration,
308+
tags: config.bootstrap?.tags,
309+
execute: config.bootstrap?.execute,
310+
trust: config.bootstrap?.trust,
311+
trustForLookup: config.bootstrap?.trustForLookup,
312+
cloudformationExecutionPolicies: config.bootstrap?.cloudformationExecutionPolicies,
313+
force: config.bootstrap?.force,
314+
terminationProtection: config.bootstrap?.terminationProtection,
315+
showTemplate: config.bootstrap?.showTemplate,
316+
toolkitStackName: config.bootstrap?.toolkitStackName,
317+
template: config.bootstrap?.template,
318+
previousParameters: config.bootstrap?.previousParameters,
319+
};
320+
const gcOptions = {
321+
action: config.gc?.action,
322+
type: config.gc?.type,
323+
rollbackBufferDays: config.gc?.rollbackBufferDays,
324+
createdBufferDays: config.gc?.createdBufferDays,
325+
confirm: config.gc?.confirm,
326+
bootstrapStackName: config.gc?.bootstrapStackName,
327+
};
328+
const deployOptions = {
329+
all: config.deploy?.all,
330+
buildExclude: config.deploy?.buildExclude,
331+
exclusively: config.deploy?.exclusively,
332+
requireApproval: config.deploy?.requireApproval,
333+
notificationArns: config.deploy?.notificationArns,
334+
tags: config.deploy?.tags,
335+
execute: config.deploy?.execute,
336+
changeSetName: config.deploy?.changeSetName,
337+
method: config.deploy?.method,
338+
importExistingResources: config.deploy?.importExistingResources,
339+
force: config.deploy?.force,
340+
parameters: config.deploy?.parameters,
341+
outputsFile: config.deploy?.outputsFile,
342+
previousParameters: config.deploy?.previousParameters,
343+
toolkitStackName: config.deploy?.toolkitStackName,
344+
progress: config.deploy?.progress,
345+
rollback: config.deploy?.rollback,
346+
hotswap: config.deploy?.hotswap,
347+
hotswapFallback: config.deploy?.hotswapFallback,
348+
watch: config.deploy?.watch,
349+
logs: config.deploy?.logs,
350+
concurrency: config.deploy?.concurrency,
351+
assetParallelism: config.deploy?.assetParallelism,
352+
assetPrebuild: config.deploy?.assetPrebuild,
353+
ignoreNoStacks: config.deploy?.ignoreNoStacks,
354+
};
355+
const rollbackOptions = {
356+
all: config.rollback?.all,
357+
toolkitStackName: config.rollback?.toolkitStackName,
358+
force: config.rollback?.force,
359+
validateBootstrapVersion: config.rollback?.validateBootstrapVersion,
360+
orphan: config.rollback?.orphan,
361+
};
362+
const importOptions = {
363+
execute: config.import?.execute,
364+
changeSetName: config.import?.changeSetName,
365+
toolkitStackName: config.import?.toolkitStackName,
366+
rollback: config.import?.rollback,
367+
force: config.import?.force,
368+
recordResourceMapping: config.import?.recordResourceMapping,
369+
resourceMapping: config.import?.resourceMapping,
370+
};
371+
const watchOptions = {
372+
buildExclude: config.watch?.buildExclude,
373+
exclusively: config.watch?.exclusively,
374+
changeSetName: config.watch?.changeSetName,
375+
force: config.watch?.force,
376+
toolkitStackName: config.watch?.toolkitStackName,
377+
progress: config.watch?.progress,
378+
rollback: config.watch?.rollback,
379+
hotswap: config.watch?.hotswap,
380+
hotswapFallback: config.watch?.hotswapFallback,
381+
logs: config.watch?.logs,
382+
concurrency: config.watch?.concurrency,
383+
};
384+
const destroyOptions = {
385+
all: config.destroy?.all,
386+
exclusively: config.destroy?.exclusively,
387+
force: config.destroy?.force,
388+
};
389+
const diffOptions = {
390+
exclusively: config.diff?.exclusively,
391+
contextLines: config.diff?.contextLines,
392+
template: config.diff?.template,
393+
strict: config.diff?.strict,
394+
securityOnly: config.diff?.securityOnly,
395+
fail: config.diff?.fail,
396+
processed: config.diff?.processed,
397+
quiet: config.diff?.quiet,
398+
changeSet: config.diff?.changeSet,
399+
};
400+
const metadataOptions = {};
401+
const acknowledgeOptions = {};
402+
const noticesOptions = {
403+
unacknowledged: config.notices?.unacknowledged,
404+
};
405+
const initOptions = {
406+
language: config.init?.language,
407+
list: config.init?.list,
408+
generateOnly: config.init?.generateOnly,
409+
};
410+
const migrateOptions = {
411+
stackName: config.migrate?.stackName,
412+
language: config.migrate?.language,
413+
account: config.migrate?.account,
414+
region: config.migrate?.region,
415+
fromPath: config.migrate?.fromPath,
416+
fromStack: config.migrate?.fromStack,
417+
outputPath: config.migrate?.outputPath,
418+
fromScan: config.migrate?.fromScan,
419+
filter: config.migrate?.filter,
420+
compress: config.migrate?.compress,
421+
};
422+
const contextOptions = {
423+
reset: config.context?.reset,
424+
force: config.context?.force,
425+
clear: config.context?.clear,
426+
};
427+
const docsOptions = {
428+
browser: config.docs?.browser,
429+
};
430+
const doctorOptions = {};
431+
const cliArguments: CliArguments = {
432+
globalOptions,
433+
list: listOptions,
434+
synthesize: synthesizeOptions,
435+
bootstrap: bootstrapOptions,
436+
gc: gcOptions,
437+
deploy: deployOptions,
438+
rollback: rollbackOptions,
439+
import: importOptions,
440+
watch: watchOptions,
441+
destroy: destroyOptions,
442+
diff: diffOptions,
443+
metadata: metadataOptions,
444+
acknowledge: acknowledgeOptions,
445+
notices: noticesOptions,
446+
init: initOptions,
447+
migrate: migrateOptions,
448+
context: contextOptions,
449+
docs: docsOptions,
450+
doctor: doctorOptions,
451+
};
452+
453+
return cliArguments;
454+
}

0 commit comments

Comments
 (0)