From b5c8f9a20f339b62759c736c7b6913046689467a Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Thu, 19 Jul 2018 18:54:27 +0300 Subject: [PATCH] Toolkit: cdk ls --long Default "ls" to just print the names of all stacks. The `--long` (or `-l`) switch can be used to emit all data. --- packages/aws-cdk/bin/cdk.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index c581732a39318..b7fe6277b7238 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -52,6 +52,7 @@ async function parseCommandLineArguments() { .option('verbose', { type: 'boolean', alias: 'v', desc: 'Show debug logs' }) .demandCommand(1) .command('list', 'Lists all stacks in the cloud executable (alias: ls)') + .option('long', { type: 'boolean', default: false, alias: 'l', desc: 'display environment information for each stack' }) // tslint:disable-next-line:max-line-length .command('synth [STACKS..]', 'Synthesizes and prints the cloud formation template for this stack (alias: synthesize, construct, cons)', yargs => yargs .option('interactive', { type: 'boolean', alias: 'i', desc: 'interactively watch and show template updates' }) @@ -167,7 +168,7 @@ async function initCommandLine() { switch (command) { case 'ls': case 'list': - return await listStacks(); + return await cliList({ long: args.long }); case 'diff': return await diffStack(await findStack(args.STACK), args.template); @@ -402,6 +403,22 @@ async function initCommandLine() { return ret; } + async function cliList(options: { long?: boolean } = { }) { + const stacks = await listStacks(); + + // if we are in "long" mode, emit the array as-is (JSON/YAML) + if (options.long) { + return stacks; // will be YAML formatted output + } + + // just print stack names + for (const stack of stacks) { + data(stack.name); + } + + return 0; // exit-code + } + async function listStacks(): Promise { const response: cxapi.ListStacksResponse = await execProgram({ type: 'list' }); return response.stacks;