fix confirm message

This commit is contained in:
Ben Irvin 2022-12-14 12:39:26 +01:00
parent 2a58152861
commit 2cfcd13ed9
2 changed files with 8 additions and 16 deletions

View File

@ -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?"
)
)

View File

@ -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,
};