Skip to content

Commit

Permalink
feat(toolkit): print available templates when --language is omitted (#…
Browse files Browse the repository at this point in the history
…1159)

When --language is omitted from a call to "cdk init", instead of
just printing the supported languages, we now print all options,
including template types.
  • Loading branch information
Elad Ben-Israel authored Nov 13, 2018
1 parent e9b4a33 commit 5726c45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function initCommandLine() {
if (args.list) {
return await printAvailableTemplates(language);
} else {
return await cliInit(args.TEMPLATE || 'default', language);
return await cliInit(args.TEMPLATE, language);
}

default:
Expand Down
11 changes: 9 additions & 2 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ const CDK_HOME = process.env.CDK_HOME ? path.resolve(process.env.CDK_HOME) : pat
/**
* Initialize a CDK package in the current directory
*/
export async function cliInit(type: string, language: string | undefined, canUseNetwork?: boolean) {
const template = (await availableInitTemplates).find(t => t.hasName(type));
export async function cliInit(type?: string, language?: string, canUseNetwork?: boolean) {
if (!type && !language) {
await printAvailableTemplates();
return;
}

type = type || 'default'; // "default" is the default type (and maps to "app")

const template = (await availableInitTemplates).find(t => t.hasName(type!));
if (!template) {
await printAvailableTemplates(language);
throw new Error(`Unknown init template: ${type}`);
Expand Down

0 comments on commit 5726c45

Please sign in to comment.