Skip to content

Commit ed1c30e

Browse files
committed
feat: add region/edge support
1 parent ee0e80b commit ed1c30e

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

Diff for: packages/plugin-serverless/src/commands/serverless/deploy.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
1+
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands;
22

33
const {
44
handler,
55
cliInfo,
66
describe,
7-
} = require('twilio-run/dist/commands/deploy');
7+
} = require("twilio-run/dist/commands/deploy");
88
const {
99
convertYargsOptionsToOclifFlags,
1010
normalizeFlags,
1111
createExternalCliOptions,
12-
} = require('../../utils');
12+
getRegionAndEdge,
13+
} = require("../../utils");
1314

1415
class FunctionsDeploy extends TwilioClientCommand {
1516
async run() {
@@ -20,6 +21,10 @@ class FunctionsDeploy extends TwilioClientCommand {
2021

2122
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2223

24+
const { edge, region } = getRegionAndEdge(flags, this);
25+
flags.region = region;
26+
flags.edge = edge;
27+
2328
const opts = Object.assign({}, flags, args);
2429
return handler(opts, externalOptions);
2530
}

Diff for: packages/plugin-serverless/src/commands/serverless/list.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
1+
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands;
22

3-
const { handler, cliInfo, describe } = require('twilio-run/dist/commands/list');
3+
const { handler, cliInfo, describe } = require("twilio-run/dist/commands/list");
44
const {
55
convertYargsOptionsToOclifFlags,
66
normalizeFlags,
77
createExternalCliOptions,
8-
} = require('../../utils');
8+
} = require("../../utils");
99

1010
class FunctionsList extends TwilioClientCommand {
1111
async run() {
@@ -16,6 +16,10 @@ class FunctionsList extends TwilioClientCommand {
1616

1717
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
1818

19+
const { edge, region } = getRegionAndEdge(flags, this);
20+
flags.region = region;
21+
flags.edge = edge;
22+
1923
const opts = Object.assign({}, flags, args);
2024
return handler(opts, externalOptions);
2125
}
@@ -25,11 +29,11 @@ FunctionsList.description = describe;
2529

2630
FunctionsList.args = [
2731
{
28-
name: 'types',
32+
name: "types",
2933
required: false,
3034
default: cliInfo.argsDefaults.types,
3135
description:
32-
'Comma separated list of things to list (services,environments,functions,assets,variables)',
36+
"Comma separated list of things to list (services,environments,functions,assets,variables)",
3337
},
3438
];
3539

Diff for: packages/plugin-serverless/src/commands/serverless/logs.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { TwilioClientCommand } = require('@twilio/cli-core').baseCommands;
1+
const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands;
22

3-
const { handler, cliInfo, describe } = require('twilio-run/dist/commands/logs');
3+
const { handler, cliInfo, describe } = require("twilio-run/dist/commands/logs");
44

55
const {
66
convertYargsOptionsToOclifFlags,
77
normalizeFlags,
88
createExternalCliOptions,
9-
} = require('../../utils');
9+
} = require("../../utils");
1010

1111
class LogsList extends TwilioClientCommand {
1212
async run() {
@@ -17,6 +17,10 @@ class LogsList extends TwilioClientCommand {
1717

1818
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
1919

20+
const { edge, region } = getRegionAndEdge(flags, this);
21+
flags.region = region;
22+
flags.edge = edge;
23+
2024
const opts = Object.assign({}, flags, args);
2125
return handler(opts, externalOptions);
2226
}

Diff for: packages/plugin-serverless/src/commands/serverless/promote.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ const { TwilioClientCommand } = require("@twilio/cli-core").baseCommands;
33
const {
44
handler,
55
cliInfo,
6-
describe
6+
describe,
77
} = require("twilio-run/dist/commands/activate");
88
const {
99
convertYargsOptionsToOclifFlags,
1010
normalizeFlags,
11-
createExternalCliOptions
11+
createExternalCliOptions,
1212
} = require("../../utils");
1313

1414
class FunctionsPromote extends TwilioClientCommand {
@@ -20,6 +20,10 @@ class FunctionsPromote extends TwilioClientCommand {
2020

2121
const externalOptions = createExternalCliOptions(flags, this.twilioClient);
2222

23+
const { edge, region } = getRegionAndEdge(flags, this);
24+
flags.region = region;
25+
flags.edge = edge;
26+
2327
const opts = Object.assign({}, flags, args);
2428
return handler(opts, externalOptions);
2529
}

Diff for: packages/plugin-serverless/src/utils.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const path = require('path');
2-
const camelCase = require('lodash.camelcase');
3-
const { flags } = require('@oclif/command');
1+
const path = require("path");
2+
const camelCase = require("lodash.camelcase");
3+
const { flags } = require("@oclif/command");
44

55
function convertYargsOptionsToOclifFlags(options) {
66
const flagsResult = Object.keys(options).reduce((result, name) => {
@@ -11,10 +11,10 @@ function convertYargsOptionsToOclifFlags(options) {
1111
hidden: opt.hidden,
1212
};
1313

14-
if (typeof opt.default !== 'undefined') {
14+
if (typeof opt.default !== "undefined") {
1515
flag.default = opt.default;
1616

17-
if (opt.type === 'boolean') {
17+
if (opt.type === "boolean") {
1818
if (flag.default === true) {
1919
flag.allowNo = true;
2020
}
@@ -37,7 +37,7 @@ function convertYargsOptionsToOclifFlags(options) {
3737

3838
function normalizeFlags(flags) {
3939
const result = Object.keys(flags).reduce((current, name) => {
40-
if (name.includes('-')) {
40+
if (name.includes("-")) {
4141
const normalizedName = camelCase(name);
4242
current[normalizedName] = flags[name];
4343
}
@@ -62,8 +62,17 @@ function createExternalCliOptions(flags, twilioClient) {
6262
};
6363
}
6464

65+
function getRegionAndEdge(flags, clientCommand) {
66+
const edge =
67+
flags.edge || process.env.TWILIO_EDGE || clientCommand.userConfig.edge;
68+
const region = flags.region || clientCommand.currentProfile.region;
69+
70+
return { edge, region };
71+
}
72+
6573
module.exports = {
6674
convertYargsOptionsToOclifFlags,
6775
normalizeFlags,
6876
createExternalCliOptions,
77+
getRegionAndEdge,
6978
};

0 commit comments

Comments
 (0)