Skip to content

Commit e88fcaa

Browse files
committed
feat: Adding validating for deployment to make choice required.
1 parent af7e4b5 commit e88fcaa

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

templates/cli/lib/questions.js.twig

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ const getInstallCommand = (runtime) => {
107107
return undefined;
108108
};
109109

110+
const deployValidate = (singular, items) => {
111+
if (items.length <= 0) {
112+
return `Please select at least one ${singular}`;
113+
}
114+
return true;
115+
}
116+
110117
const questionsInitProject = [
111118
{
112119
type: "confirm",
@@ -209,12 +216,12 @@ const questionsInitFunction = [
209216
parseOutput: false
210217
})
211218
let runtimes = response["runtimes"]
212-
let choices = runtimes.map((runtime, idx) => {
219+
let choices = runtimes.map((runtime, idx) => {
213220
return {
214221
name: `${runtime.name} (${runtime['$id']})`,
215-
value: {
216-
id: runtime['$id'],
217-
entrypoint: getEntrypoint(runtime['$id']),
222+
value: {
223+
id: runtime['$id'],
224+
entrypoint: getEntrypoint(runtime['$id']),
218225
ignore: getIgnores(runtime['$id']),
219226
commands : getInstallCommand(runtime['$id'])
220227
},
@@ -281,6 +288,7 @@ const questionsDeployFunctions = [
281288
type: "checkbox",
282289
name: "functions",
283290
message: "Which functions would you like to deploy?",
291+
validate: (i) => deployValidate('function', i),
284292
choices: () => {
285293
let functions = localConfig.getFunctions();
286294
if (functions.length === 0) {
@@ -307,6 +315,7 @@ const questionsDeployCollections = [
307315
type: "checkbox",
308316
name: "collections",
309317
message: "Which collections would you like to deploy?",
318+
validate: (i) => deployValidate('collection', i),
310319
choices: () => {
311320
let collections = localConfig.getCollections();
312321
if (collections.length === 0) {
@@ -332,6 +341,7 @@ const questionsDeployBuckets = [
332341
type: "checkbox",
333342
name: "buckets",
334343
message: "Which buckets would you like to deploy?",
344+
validate: (i) => deployValidate('bucket', i),
335345
choices: () => {
336346
let buckets = localConfig.getBuckets();
337347
if (buckets.length === 0) {
@@ -372,6 +382,7 @@ const questionsDeployTeams = [
372382
type: "checkbox",
373383
name: "teams",
374384
message: "Which teams would you like to deploy?",
385+
validate: (i) => deployValidate('team', i),
375386
choices: () => {
376387
let teams = localConfig.getTeams();
377388
if (teams.length === 0) {
@@ -403,7 +414,7 @@ const questionsListFactors = [
403414
sdk: client,
404415
parseOutput: false
405416
});
406-
417+
407418
const choices = [
408419
{
409420
name: `TOTP (Time-based One-time Password)`,

0 commit comments

Comments
 (0)