Skip to content

Commit

Permalink
Toolkit: cdk ls --long (#380)
Browse files Browse the repository at this point in the history
Default "ls" to just print the names of all stacks.
The `--long` (or `-l`) switch can be used to emit all data.
  • Loading branch information
Elad Ben-Israel authored Jul 23, 2018
1 parent 54fc3f6 commit 5209555
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<cxapi.StackInfo[]> {
const response: cxapi.ListStacksResponse = await execProgram({ type: 'list' });
return response.stacks;
Expand Down

0 comments on commit 5209555

Please sign in to comment.