Skip to content
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

Toolkit: cdk ls --long #380

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return stacks.map(s => s.name);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that will cause a JSON/YAML array to be returned:

- stack1
- stack2
- stack3

And I want an "xargs-compatible" output:

stack1
stack2
stack3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. As a user I would sometimes find this convenient, sometimes find it confusing. I wonder if long shouldn't be the default, and the xargs-compatible be the option...

Anyway -- that is no blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ls should behave like "ls", where --long is not the default 😉

}

return 0; // exit-code
}

async function listStacks(): Promise<cxapi.StackInfo[]> {
const response: cxapi.ListStacksResponse = await execProgram({ type: 'list' });
return response.stacks;
Expand Down