Skip to content
This repository was archived by the owner on Feb 3, 2022. It is now read-only.

Commit 169c000

Browse files
committed
Makes Twilio credentials optional
Previously, validating that the account sid looked like an account sid lead to the option being mandatory. This updates the prompt to not worry if the account sid is an empty string. It also adds a --skip-credentials option to avoid the tool prompting at all. Fixes #3.
1 parent c7e79f3 commit 169c000

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/cli.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ function cli(cwd) {
1919
type: 'string'
2020
});
2121
command.options({
22-
accountSid: {
22+
'account-sid': {
2323
alias: 'a',
2424
describe: 'The Account SID for your Twilio account',
2525
type: 'string'
2626
},
27-
authToken: {
27+
'auth-token': {
2828
alias: 't',
2929
describe: 'Your Twilio account Auth Token',
3030
type: 'string'
31+
},
32+
'skip-credentials': {
33+
describe: "Don't ask for Twilio account credentials",
34+
type: 'boolean',
35+
default: false
3136
}
3237
});
3338
},

src/create-twilio-function/prompt.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
const inquirer = require('inquirer');
22

33
async function promptForAccountDetails(config) {
4+
if (config.skipCredentials) return {};
45
const questions = [];
5-
if (!config.accountSid) {
6+
if (typeof config.accountSid === 'undefined') {
67
questions.push({
78
type: 'input',
89
name: 'accountSid',
910
message: 'Twilio Account SID',
10-
validate: input =>
11-
input.startsWith('AC') ? true : 'An Account SID starts with "AC".'
11+
validate: input => {
12+
return input.startsWith('AC') || input === ''
13+
? true
14+
: 'An Account SID starts with "AC".';
15+
}
1216
});
1317
}
14-
if (!config.authToken) {
18+
if (typeof config.authToken === 'undefined') {
1519
questions.push({
1620
type: 'password',
1721
name: 'authToken',

src/create-twilio-function/prompt.test.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('promptForAccountDetails', () => {
77
test(`should ask for an accountSid if not specified`, async () => {
88
inquirer.prompt = jest.fn(() =>
99
Promise.resolve({
10-
accountSid: 'test-sid',
10+
accountSid: 'AC1234',
1111
authToken: 'test-auth-token'
1212
})
1313
);
@@ -21,13 +21,12 @@ describe('promptForAccountDetails', () => {
2121
test(`should ask for an auth if not specified`, async () => {
2222
inquirer.prompt = jest.fn(() =>
2323
Promise.resolve({
24-
accountSid: 'test-sid',
2524
authToken: 'test-auth-token'
2625
})
2726
);
2827
await promptForAccountDetails({
2928
name: 'function-test',
30-
accountSid: 'test-sid'
29+
accountSid: 'AC1234'
3130
});
3231
expect(inquirer.prompt).toHaveBeenCalledTimes(1);
3332
expect(inquirer.prompt).toHaveBeenCalledWith(expect.any(Array));
@@ -36,16 +35,24 @@ describe('promptForAccountDetails', () => {
3635
test(`should not prompt if account sid and auth token specified`, async () => {
3736
inquirer.prompt = jest.fn(() =>
3837
Promise.resolve({
39-
accountSid: 'test-sid',
38+
accountSid: 'AC1234',
4039
authToken: 'test-auth-token'
4140
})
4241
);
4342
await promptForAccountDetails({
4443
name: 'function-test',
45-
accountSid: 'test-sid',
46-
authToken: 'test-auth-token'
44+
accountSid: 'AC5678',
45+
authToken: 'other-test-token'
4746
});
4847
expect(inquirer.prompt).toHaveBeenCalledTimes(1);
4948
expect(inquirer.prompt).toHaveBeenCalledWith([]);
5049
});
50+
51+
test(`should not ask for credentials if skip-credentials flag is true`, async () => {
52+
inquirer.prompt = jest.fn(() => {});
53+
await promptForAccountDetails({
54+
skipCredentials: true
55+
});
56+
expect(inquirer.prompt).not.toHaveBeenCalled();
57+
});
5158
});

0 commit comments

Comments
 (0)