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

Print 'No results' when outputting an empty result #28

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/base-commands/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class BaseCommand extends Command {

output(fullData, properties, options) {
const dataArray = fullData.constructor === Array ? fullData : [fullData];

if (dataArray.length === 0) {
this.logger.info('No results');
return;
}

const limitedData = properties ? this.getLimitedData(dataArray, properties) : null;

process.stdout.write(this.outputProcessor(dataArray, limitedData || dataArray, options) + '\n');
Expand Down
6 changes: 6 additions & 0 deletions test/base-commands/base-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ describe('base-commands', () => {
expect(ctx.stderr).to.contain('"barn" is not a valid property name.');
});

outputTest.stderr().it('should output a message when the array is empty', async ctx => {
ctx.testCmd.output([]);
expect(ctx.stdout).to.be.empty;
expect(ctx.stderr).to.contain('No results');
});

test
.twilioCliEnv(Config)
.do(async ctx => {
Expand Down