@@ -5,7 +5,7 @@ const { Command } = require("commander");
5
5
const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config");
6
6
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
7
7
const { paginate } = require('../paginate');
8
- const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
8
+ const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsGetEntrypoint, questionsPushCollections, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
9
9
const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser");
10
10
const { proxyListRules } = require('./proxy');
11
11
const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
@@ -340,6 +340,33 @@ const awaitPools = {
340
340
},
341
341
}
342
342
343
+ const getConfirmation = async () => {
344
+ if (!cliConfig.force) {
345
+ async function fixConfirmation() {
346
+ const answers = await inquirer.prompt(questionPushChangesConfirmation);
347
+ if(answers.changes !== 'YES' && answers.changes !== 'NO') {
348
+ return await fixConfirmation();
349
+ }
350
+
351
+ return answers.changes;
352
+ }
353
+
354
+ let answers = await inquirer.prompt(questionPushChanges);
355
+ if(answers.changes !== 'YES' && answers.changes !== 'NO') {
356
+ answers.changes = await fixConfirmation();
357
+ }
358
+
359
+ if (answers.changes === 'YES') {
360
+ return true;
361
+ }
362
+
363
+ warn('Skipping push action. Changes were not applied.');
364
+ return false;
365
+ }
366
+
367
+ return true;
368
+ };
369
+
343
370
const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
344
371
log('Checking for changes');
345
372
const changes = [];
@@ -385,11 +412,8 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName,
385
412
}
386
413
387
414
drawTable(changes);
388
- if (!cliConfig.force) {
389
- const answers = await inquirer.prompt(questionPushChanges);
390
- if (answers.changes.toLowerCase() === 'yes') {
391
- return true;
392
- }
415
+ if((await getConfirmation()) === true) {
416
+ return true;
393
417
}
394
418
395
419
success(`Successfully pushed 0 ${resourcePlural}.`);
@@ -769,9 +793,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
769
793
log(`Attribute recreation will cause ${chalk.red('loss of data')}`);
770
794
}
771
795
772
- const answers = await inquirer.prompt(questionPushChanges);
773
-
774
- if (answers.changes.toLowerCase() !== 'yes') {
796
+ if((await getConfirmation()) !== true) {
775
797
return changedAttributes;
776
798
}
777
799
}
@@ -893,12 +915,9 @@ const pushSettings = async () => {
893
915
894
916
if (changes.length > 0) {
895
917
drawTable(changes);
896
- if (!cliConfig.force) {
897
- const answers = await inquirer.prompt(questionPushChanges);
898
- if (answers.changes.toLowerCase() !== 'yes') {
899
- success(`Successfully pushed 0 project settings.`);
900
- return;
901
- }
918
+ if((await getConfirmation()) !== true) {
919
+ success(`Successfully pushed 0 project settings.`);
920
+ return;
902
921
}
903
922
}
904
923
} catch (e) {
@@ -1391,10 +1410,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
1391
1410
throw e;
1392
1411
}
1393
1412
numberOfCollections++;
1394
- success(`Pushed ${collection.name} ( ${collection['$id']} )`);
1413
+ success(`Successfully pushed ${collection.name} ( ${collection['$id']} )`);
1395
1414
}
1396
1415
1397
- success(`Pushed ${numberOfCollections} collections`);
1416
+ success(`Successfully pushed ${numberOfCollections} collections`);
1398
1417
}
1399
1418
1400
1419
const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => {
@@ -1557,7 +1576,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
1557
1576
1558
1577
let topicsIds = [];
1559
1578
const configTopics = localConfig.getMessagingTopics();
1560
- let overrideExisting = cliConfig.force;
1561
1579
1562
1580
if (cliConfig.all) {
1563
1581
checkDeployConditions(localConfig);
@@ -1584,13 +1602,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
1584
1602
topics.push(...idTopic);
1585
1603
}
1586
1604
1587
- if (!cliConfig.force) {
1588
- const answers = await inquirer.prompt(questionsPushMessagingTopics[1])
1589
- if (answers.override.toLowerCase() === "yes") {
1590
- overrideExisting = true;
1591
- }
1592
- }
1593
-
1594
1605
if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) {
1595
1606
return;
1596
1607
}
@@ -1607,11 +1618,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
1607
1618
})
1608
1619
log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`);
1609
1620
1610
- if (!overrideExisting) {
1611
- log(`Skipping ${topic.name} ( ${topic['$id']} )`);
1612
- continue;
1613
- }
1614
-
1615
1621
await messagingUpdateTopic({
1616
1622
topicId: topic['$id'],
1617
1623
name: topic.name,
0 commit comments