Skip to content

Commit

Permalink
feat: Add flag no header for fetch and list commands. (#344)
Browse files Browse the repository at this point in the history
* feat: Adding --no-header flag for list commands

* Added the test cases

Co-authored-by: Sindhura Chamala <[email protected]>
  • Loading branch information
ravali-rimmalapudi and Sindhura3 authored Dec 3, 2021
1 parent a072f8c commit d26f504
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/base-commands/twilio-api-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ TwilioApiCommand.setUpNewCommandClass = (NewCommandClass) => {
});
}

if (
NewCommandClass.actionDefinition.commandName === 'list' ||
NewCommandClass.actionDefinition.commandName === 'fetch'
) {
cmdFlags = Object.assign(cmdFlags, TwilioClientCommand.noHeader);
}

// 'list' commands get limit flags for specifying the result set size.
if (NewCommandClass.actionDefinition.commandName === 'list') {
cmdFlags = Object.assign(cmdFlags, TwilioClientCommand.limitFlags);
Expand Down
1 change: 1 addition & 0 deletions src/commands/debugger/logs/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ DebuggerLogsList.flags = {
}),
...DebuggerLogsList.PropertyFlags,
...TwilioClientCommand.flags,
...TwilioClientCommand.noHeader,
};

module.exports = DebuggerLogsList;
1 change: 1 addition & 0 deletions src/commands/phone-numbers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NumberList.flags = {
}),
...TwilioClientCommand.flags,
...TwilioClientCommand.accountSidFlag,
...TwilioClientCommand.noHeader,
};

module.exports = NumberList;
4 changes: 2 additions & 2 deletions src/commands/profiles/list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chalk = require('chalk');
const { BaseCommand } = require('@twilio/cli-core').baseCommands;
const { BaseCommand, TwilioClientCommand } = require('@twilio/cli-core').baseCommands;

class ProfilesList extends BaseCommand {
async run() {
Expand Down Expand Up @@ -33,6 +33,6 @@ class ProfilesList extends BaseCommand {
}

ProfilesList.description = 'show what profiles you have configured';
ProfilesList.flags = BaseCommand.flags;
ProfilesList.flags = { ...BaseCommand.flags, ...TwilioClientCommand.noHeader };

module.exports = ProfilesList;
2 changes: 2 additions & 0 deletions test/base-commands/twilio-api-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ describe('base-commands', () => {
expect(Object.keys(NewCommandClass.flags)).to.include('start-time-before');
expect(Object.keys(NewCommandClass.flags)).to.include('limit');
expect(Object.keys(NewCommandClass.flags)).to.include('no-limit');
expect(Object.keys(NewCommandClass.flags)).to.include('no-header');
});

test.it('checks the help document url', () => {
const NewCommandClass = getCommandClass(callCreateActionDefinition);
expect(NewCommandClass.id).to.equal('api:core:calls:create');
expect(NewCommandClass.description).to.equal(fakeResource.actions.create.description);
expect(NewCommandClass.docLink).to.equal('https://twilio.com/docs/usage/api');
expect(Object.keys(NewCommandClass.flags)).not.to.include('no-header');
});

test.it('checks the help document url', () => {
Expand Down
23 changes: 23 additions & 0 deletions test/commands/debugger/logs/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ describe('debugger:logs:list', () => {
.it('streams and then quits', (ctx) => {
expect(ctx.stdout.match(INFO_LOG.error_code)).to.have.length(1);
expect(ctx.stdout.match(WARN_LOG.alert_text)).to.have.length(1);
expect(ctx.stdout).to.contain('Date Created');
});

testConfig
.nock('https://monitor.twilio.com', (api) => {
api
.get('/v1/Alerts')
.query(true)
.times(2)
.reply(200, { alerts: [INFO_LOG, WARN_LOG, INFO_LOG] })
.get('/v1/Alerts')
.query(true)
.reply(404, { code: 999, message: 'Some random error' });
})
.twilioCommand(DebuggerLogsList, ['--streaming', '--no-header'])
.catch(/999.*Some random error/)
.it('streams and then quits and displays with --no-header', (ctx) => {
expect(ctx.stdout).not.to.contain('Date Created');
expect(ctx.stdout).not.to.contain('Log Level');
expect(ctx.stdout).not.to.contain('Error Code');
expect(ctx.stdout).not.to.contain('Alert Text');
expect(ctx.stdout.match(INFO_LOG.error_code)).to.have.length(1);
expect(ctx.stdout.match(WARN_LOG.alert_text)).to.have.length(1);
});

testConfig
Expand Down
3 changes: 3 additions & 0 deletions test/commands/phone-numbers/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ describe('commands', () => {
setUpTest(['--properties', 'phoneNumber']).it('runs incoming-phone-number:list with custom properties', (ctx) => {
expect(ctx.stdout).to.equal('Phone Number\n+12095551212\n');
});
setUpTest(['--no-header']).it('runs incoming-phone-number:list --no-header', (ctx) => {
expect(ctx.stdout).to.equal('PN123 +12095551212 my phone #\n');
});
});
});
});
21 changes: 21 additions & 0 deletions test/commands/profiles/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ describe('commands', () => {
expect(ctx.stdout.match(/true/g)).to.have.length(1);
expect(ctx.stdout).to.match(/profile1.*true/);
expect(ctx.stderr).to.equal('');
expect(ctx.stdout).to.contain('ID');
});

test
.do((ctx) => {
ctx.userConfig = new ConfigData();
ctx.userConfig.addProfile('profile1', constants.FAKE_ACCOUNT_SID);
ctx.userConfig.addProfile('profile2', constants.FAKE_ACCOUNT_SID);
ctx.userConfig.activeProfile = 'profile1';
})
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProfilesList, ['--no-header'])
.it('list with --no-header', (ctx) => {
expect(ctx.stdout).not.to.contain('ID');
expect(ctx.stdout).not.to.contain('Account SID');
expect(ctx.stdout).not.to.contain('Active');
expect(ctx.stdout).to.contain('profile1');
expect(ctx.stdout).to.contain('profile2');
expect(ctx.stdout).to.contain(constants.FAKE_ACCOUNT_SID);
});

test
Expand Down

0 comments on commit d26f504

Please sign in to comment.