@@ -5,7 +5,7 @@ const { Command } = require("commander");
55const { localConfig, globalConfig, KeysAttributes, KeysFunction, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, } = require("../config");
66const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
77const { 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");
99const { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable } = require("../parser");
1010const { proxyListRules } = require('./proxy');
1111const { functionsGet, functionsCreate, functionsUpdate, functionsCreateDeployment, functionsGetDeployment, functionsListVariables, functionsDeleteVariable, functionsCreateVariable } = require('./functions');
@@ -340,6 +340,33 @@ const awaitPools = {
340340 },
341341}
342342
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+
343370const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = []) => {
344371 log('Checking for changes');
345372 const changes = [];
@@ -385,11 +412,8 @@ const approveChanges = async (resource, resourceGetFunction, keys, resourceName,
385412 }
386413
387414 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;
393417 }
394418
395419 success(`Successfully pushed 0 ${resourcePlural}.`);
@@ -769,9 +793,7 @@ const attributesToCreate = async (remoteAttributes, localAttributes, collection,
769793 log(`Attribute recreation will cause ${chalk.red('loss of data')}`);
770794 }
771795
772- const answers = await inquirer.prompt(questionPushChanges);
773-
774- if (answers.changes.toLowerCase() !== 'yes') {
796+ if((await getConfirmation()) !== true) {
775797 return changedAttributes;
776798 }
777799 }
@@ -893,12 +915,9 @@ const pushSettings = async () => {
893915
894916 if (changes.length > 0) {
895917 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;
902921 }
903922 }
904923 } catch (e) {
@@ -1391,10 +1410,10 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
13911410 throw e;
13921411 }
13931412 numberOfCollections++;
1394- success(`Pushed ${collection.name} ( ${collection['$id']} )`);
1413+ success(`Successfully pushed ${collection.name} ( ${collection['$id']} )`);
13951414 }
13961415
1397- success(`Pushed ${numberOfCollections} collections`);
1416+ success(`Successfully pushed ${numberOfCollections} collections`);
13981417}
13991418
14001419const pushBucket = async ({ returnOnZero } = { returnOnZero: false }) => {
@@ -1557,7 +1576,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
15571576
15581577 let topicsIds = [];
15591578 const configTopics = localConfig.getMessagingTopics();
1560- let overrideExisting = cliConfig.force;
15611579
15621580 if (cliConfig.all) {
15631581 checkDeployConditions(localConfig);
@@ -1584,13 +1602,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
15841602 topics.push(...idTopic);
15851603 }
15861604
1587- if (!cliConfig.force) {
1588- const answers = await inquirer.prompt(questionsPushMessagingTopics[1])
1589- if (answers.override.toLowerCase() === "yes") {
1590- overrideExisting = true;
1591- }
1592- }
1593-
15941605 if (!(await approveChanges(topics, messagingGetTopic, KeysTopics, 'topicId', 'topics'))) {
15951606 return;
15961607 }
@@ -1607,11 +1618,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
16071618 })
16081619 log(`Topic ${topic.name} ( ${topic['$id']} ) already exists.`);
16091620
1610- if (!overrideExisting) {
1611- log(`Skipping ${topic.name} ( ${topic['$id']} )`);
1612- continue;
1613- }
1614-
16151621 await messagingUpdateTopic({
16161622 topicId: topic['$id'],
16171623 name: topic.name,
0 commit comments