From e8ce7899433a170ff9049dae5d4763291b72123a Mon Sep 17 00:00:00 2001 From: Marco Lipparini <1532277+liarco@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:41:39 +0200 Subject: [PATCH] Adding "--force" flag to some commands (#1) * Adding "--force" flag to "drop" command * Adding "--force" flag to "import" command --- .github/workflows/lint.yml | 2 +- src/index.ts | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9538230..8395f2b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,5 @@ name: Lint -on: [push, pull_request] +on: [pull_request] jobs: lint: diff --git a/src/index.ts b/src/index.ts index 3c789f5..74eff0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -127,14 +127,17 @@ program .command('drop') .description('Drops the given database and its default user (if they exist)') .argument('', 'The database name') - .action(async (databaseName) => { + .option('-f,--force', 'Skip safety confirmation', false) + .action(async (databaseName, options) => { const username = databaseName; const userPwd = `${databaseName}-pwd`; - const confirmation = await confirm({ - message: `This action will delete your database "${databaseName}" and cannot be reverted. Are you sure?`, - default: false, - }); + const confirmation = + options.force === true || + (await confirm({ + message: `This action will delete your database "${databaseName}" and cannot be reverted. Are you sure?`, + default: false, + })); if (confirmation !== true) { console.info('Aborting...'); @@ -200,11 +203,14 @@ program .command('import') .description('Runs all queries from the given SQL file') .argument('', 'The SQL file to import') - .action(async (sqlFilePath) => { - const confirmation = await confirm({ - message: 'This action will execute any SQL statement found in the given file and cannot be reverted. Are you sure?', - default: false, - }); + .option('-f,--force', 'Skip safety confirmation', false) + .action(async (sqlFilePath, options) => { + const confirmation = + options.force === true || + (await confirm({ + message: 'This action will execute any SQL statement found in the given file and cannot be reverted. Are you sure?', + default: false, + })); if (confirmation !== true) { console.info('Aborting...');