From 2cfcd13ed994f78fa574f8ed43026ebdb9d9bea5 Mon Sep 17 00:00:00 2001 From: Ben Irvin Date: Wed, 14 Dec 2022 12:39:26 +0100 Subject: [PATCH] fix confirm message --- packages/core/strapi/bin/strapi.js | 6 ++---- .../strapi/lib/commands/utils/commander.js | 18 ++++++------------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/core/strapi/bin/strapi.js b/packages/core/strapi/bin/strapi.js index 260bdb21e3..e6025cf9da 100755 --- a/packages/core/strapi/bin/strapi.js +++ b/packages/core/strapi/bin/strapi.js @@ -14,7 +14,7 @@ const inquirer = require('inquirer'); const program = new Command(); const packageJSON = require('../package.json'); -const { promptEncryptionKey, confirmKeyValue } = require('../lib/commands/utils/commander'); +const { promptEncryptionKey, confirmMessage } = require('../lib/commands/utils/commander'); const checkCwdIsStrapiApp = (name) => { const logErrorAndExit = () => { @@ -326,9 +326,7 @@ program }) .hook( 'preAction', - confirmKeyValue( - 'conflictStrategy', - 'restore', + confirmMessage( "Using strategy 'restore' will delete all data in your database. Are you sure you want to proceed?" ) ) diff --git a/packages/core/strapi/lib/commands/utils/commander.js b/packages/core/strapi/lib/commands/utils/commander.js index 8430845743..8c9ce354d4 100644 --- a/packages/core/strapi/lib/commands/utils/commander.js +++ b/packages/core/strapi/lib/commands/utils/commander.js @@ -48,25 +48,19 @@ const promptEncryptionKey = async (thisCommand) => { }; /** - * hook: confirm that key has a value with a provided message + * hook: require a confirmation message to be accepted */ -const confirmKeyValue = (key, value, message) => { - return async (thisCommand) => { - const opts = thisCommand.opts(); - - if (!opts[key] || opts[key] !== value) { - console.error(`Could not confirm key ${key}, halting operation.`); - process.exit(1); - } +const confirmMessage = (message) => { + return async () => { const answers = await inquirer.prompt([ { type: 'confirm', message, - name: `confirm_${key}`, + name: `confirm`, default: false, }, ]); - if (!answers[`confirm_${key}`]) { + if (!answers.confirm) { process.exit(0); } }; @@ -75,5 +69,5 @@ const confirmKeyValue = (key, value, message) => { module.exports = { parseInputList, promptEncryptionKey, - confirmKeyValue, + confirmMessage, };