Skip to content

Commit

Permalink
Switch the 'project' topic to 'projects' (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
childish-sambino authored Jun 6, 2019
1 parent 5713ed9 commit b1ddfd9
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ All debug, informational, warning, and error information is sent to `stderr`. Th

### Multiple Twilio accounts/projects

When you run `twilio login` (an alias for `twilio project:add`), it stores your credentials and associates them with the provided project ID. The first project added will default to being the "active" project. The active project is used for all subsequent commands.
When you run `twilio login` (an alias for `twilio projects:add`), it stores your credentials and associates them with the provided project ID. The first project added will default to being the "active" project. The active project is used for all subsequent commands.

To add additional projects, run `twilio login` again but provide a different project ID (like, `my_other_proj`). Then, when you run subsequent commands, just include `-p my_other_proj` in the command (e.g. `twilio phone-numbers:list -p my_other_proj`).

Alternatively, you may switch which project is active using the `twilio project:use` command. To see the full list of local projects (including which project is active), run `twilio project:list`.
Alternatively, you may switch which project is active using the `twilio projects:use` command. To see the full list of local projects (including which project is active), run `twilio projects:list`.

### Want to use environment variables instead of creating a project?

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"phone-numbers": {
"description": "manage Twilio phone numbers"
},
"project": {
"projects": {
"description": "manage credentials for Twilio projects"
}
},
Expand Down
10 changes: 5 additions & 5 deletions src/commands/login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const ProjectAdd = require('./project/add');
const ProjectsAdd = require('./projects/add');

class Login extends ProjectAdd {
class Login extends ProjectsAdd {
}

Login.aliases = ['project:add'];
Login.flags = ProjectAdd.flags;
Login.args = ProjectAdd.args;
Login.aliases = ['projects:add'];
Login.flags = ProjectsAdd.flags;
Login.args = ProjectsAdd.args;

module.exports = Login;
18 changes: 9 additions & 9 deletions src/commands/project/add.js → src/commands/projects/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const FRIENDLY_STORAGE_LOCATIONS = {
[STORAGE_LOCATIONS.LIBSECRET]: 'using libsecret'
};

class ProjectAdd extends BaseCommand {
class ProjectsAdd extends BaseCommand {
constructor(argv, config, secureStorage) {
super(argv, config, secureStorage);

Expand Down Expand Up @@ -58,7 +58,7 @@ class ProjectAdd extends BaseCommand {
if (!this.projectId) {
const answer = await this.inquirer.prompt([{
name: 'projectId',
message: ProjectAdd.flags.project.description
message: ProjectsAdd.flags.project.description
}]);
this.projectId = answer.projectId;
}
Expand All @@ -68,7 +68,7 @@ class ProjectAdd extends BaseCommand {
if (!this.accountSid) {
this.questions.push({
name: 'accountSid',
message: ProjectAdd.args[0].description + ':',
message: ProjectsAdd.args[0].description + ':',
validate: input => Boolean(input)
});
}
Expand All @@ -79,7 +79,7 @@ class ProjectAdd extends BaseCommand {
this.questions.push({
type: 'password',
name: 'authToken',
message: ProjectAdd.flags['auth-token'].description,
message: ProjectsAdd.flags['auth-token'].description,
validate: input => Boolean(input)
});
}
Expand Down Expand Up @@ -188,10 +188,10 @@ class ProjectAdd extends BaseCommand {
}
}

ProjectAdd.aliases = ['login'];
ProjectAdd.description = 'add credentials for an existing Twilio project';
ProjectsAdd.aliases = ['login'];
ProjectsAdd.description = 'add credentials for an existing Twilio project';

ProjectAdd.flags = Object.assign(
ProjectsAdd.flags = Object.assign(
{
'auth-token': flags.string({
description: 'Your Twilio Auth Token for your Twilio project'
Expand All @@ -207,11 +207,11 @@ ProjectAdd.flags = Object.assign(
TwilioClientCommand.flags // Yes! We _do_ want the same flags as TwilioClientCommand
);

ProjectAdd.args = [
ProjectsAdd.args = [
{
name: 'account-sid',
description: 'The Account SID for your Twilio project'
}
];

module.exports = ProjectAdd;
module.exports = ProjectsAdd;
10 changes: 5 additions & 5 deletions src/commands/project/list.js → src/commands/projects/list.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const chalk = require('chalk');
const { BaseCommand } = require('@twilio/cli-core').baseCommands;

class ProjectList extends BaseCommand {
class ProjectsList extends BaseCommand {
async run() {
await super.run();
if (this.userConfig.projects.length > 0) {
Expand All @@ -19,12 +19,12 @@ class ProjectList extends BaseCommand {
activeProject.active = true;
this.output(this.userConfig.projects);
} else {
this.logger.warn('No projects have been configured. Run ' + chalk.whiteBright('twilio project:add') + ' to add one!');
this.logger.warn('No projects have been configured. Run ' + chalk.whiteBright('twilio projects:add') + ' to add one!');
}
}
}

ProjectList.description = 'show what Twilio projects you have configured';
ProjectList.flags = BaseCommand.flags;
ProjectsList.description = 'show what Twilio projects you have configured';
ProjectsList.flags = BaseCommand.flags;

module.exports = ProjectList;
module.exports = ProjectsList;
12 changes: 6 additions & 6 deletions src/commands/project/use.js → src/commands/projects/use.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { BaseCommand } = require('@twilio/cli-core').baseCommands;

class ProjectUse extends BaseCommand {
class ProjectsUse extends BaseCommand {
async run() {
await super.run();

const project = this.userConfig.getProjectById(this.args.project);
if (!project) {
this.logger.error('The project "' + this.args.project + '" does not exist. Run "twilio project:list" to see the list of configured projects.');
this.logger.error('The project "' + this.args.project + '" does not exist. Run "twilio projects:list" to see the list of configured projects.');
this.exit(1);
}
this.userConfig.activeProject = this.args.project;
Expand All @@ -15,15 +15,15 @@ class ProjectUse extends BaseCommand {
this.logger.info(configSavedMessage);
}
}
ProjectUse.description = 'select which project to use';
ProjectsUse.description = 'select which project to use';

ProjectUse.args = [
ProjectsUse.args = [
{
name: 'project',
description: 'Shorthand identifier for your Twilio project',
required: true
}
];
ProjectUse.flags = BaseCommand.flags;
ProjectsUse.flags = BaseCommand.flags;

module.exports = ProjectUse;
module.exports = ProjectsUse;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
const sinon = require('sinon');
const { expect, test, constants } = require('@twilio/cli-test');
const { Config, ConfigData } = require('@twilio/cli-core').services.config;
const ProjectAdd = require('../../../src/commands/project/add');
const ProjectsAdd = require('../../../src/commands/projects/add');
const helpMessages = require('../../../src/services/messaging/help-messages');

describe('commands', () => {
describe('project', () => {
describe('projects', () => {
describe('add', () => {
const addTest = (commandArgs = []) => test
.twilioFakeProject(ConfigData)
.twilioCliEnv(Config)
.twilioCreateCommand(ProjectAdd, commandArgs)
.twilioCreateCommand(ProjectsAdd, commandArgs)
.stdout()
.stderr()
.do(ctx => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('commands', () => {
});
})
.do(ctx => ctx.testCmd.run())
.it('runs project:add', ctx => {
.it('runs projects:add', ctx => {
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain(helpMessages.AUTH_TOKEN_NOT_SAVED);
expect(ctx.stderr).to.contain('Saved default.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { expect, test, constants } = require('@twilio/cli-test');
const { Config, ConfigData } = require('@twilio/cli-core').services.config;
const ProjectList = require('../../../src/commands/project/list');
const ProjectsList = require('../../../src/commands/projects/list');

describe('commands', () => {
describe('project', () => {
describe('projects', () => {
describe('list', () => {
test
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProjectList, [])
.it('runs project:list with no projects', ctx => {
.twilioCommand(ProjectsList, [])
.it('runs projects:list with no projects', ctx => {
expect(ctx.stdout).to.equal('');
expect(ctx.stderr).to.contain('No projects have been configured');
});
Expand All @@ -23,8 +23,8 @@ describe('commands', () => {
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProjectList, [])
.it('runs project:list with 1 project', ctx => {
.twilioCommand(ProjectsList, [])
.it('runs projects:list with 1 project', ctx => {
expect(ctx.stdout).to.contain('project1');
expect(ctx.stdout).to.contain(constants.FAKE_ACCOUNT_SID);
expect(ctx.stdout).to.not.contain('Region');
Expand All @@ -41,8 +41,8 @@ describe('commands', () => {
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProjectList, [])
.it('runs project:list with multiple projects', ctx => {
.twilioCommand(ProjectsList, [])
.it('runs projects:list with multiple projects', ctx => {
expect(ctx.stdout).to.contain('project1');
expect(ctx.stdout).to.contain('project2');
expect(ctx.stdout).to.contain(constants.FAKE_ACCOUNT_SID);
Expand All @@ -61,7 +61,7 @@ describe('commands', () => {
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProjectList, [])
.twilioCommand(ProjectsList, [])
.it('when the active project is set', ctx => {
expect(ctx.stdout).to.contain('project1');
expect(ctx.stdout).to.contain('project2');
Expand All @@ -80,8 +80,8 @@ describe('commands', () => {
.twilioCliEnv(Config)
.stdout()
.stderr()
.twilioCommand(ProjectList, [])
.it('runs project:list with 1 regional project', ctx => {
.twilioCommand(ProjectsList, [])
.it('runs projects:list with 1 regional project', ctx => {
expect(ctx.stdout).to.contain('default');
expect(ctx.stdout).to.contain(constants.FAKE_ACCOUNT_SID);
expect(ctx.stdout).to.contain('dev');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { expect, test, constants } = require('@twilio/cli-test');
const { Config, ConfigData } = require('@twilio/cli-core').services.config;
const ProjectUse = require('../../../src/commands/project/use');
const ProjectsUse = require('../../../src/commands/projects/use');

describe('commands', () => {
describe('project', () => {
describe('projects', () => {
describe('use', () => {
const setup = () => test
.stdout()
Expand All @@ -14,10 +14,10 @@ describe('commands', () => {
})
.twilioCliEnv(Config);

setup().twilioCommand(ProjectUse, ['identity']).it('should set the active project with id', ctx => {
setup().twilioCommand(ProjectsUse, ['identity']).it('should set the active project with id', ctx => {
expect(ctx.stderr).to.contain('set identity as active project');
});
setup().twilioCommand(ProjectUse, ['incorrectId']).exit(1).it('run project:active with non-existing project', ctx => {
setup().twilioCommand(ProjectsUse, ['incorrectId']).exit(1).it('run projects:active with non-existing project', ctx => {
expect(ctx.stderr).to.contain('does not exist');
});
});
Expand Down
2 changes: 1 addition & 1 deletion welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.log('* twilio login
console.log('* *');
console.log('* OR *');
console.log('* *');
console.log('* twilio project:add *');
console.log('* twilio projects:add *');
console.log('* *');
console.log('*************************************************************************');
console.log();

0 comments on commit b1ddfd9

Please sign in to comment.