diff --git a/package.json b/package.json index 47bfd6839..2913cb301 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "vip-dev-env-start": "dist/bin/vip-dev-env-start.js", "vip-dev-env-stop": "dist/bin/vip-dev-env-stop.js", "vip-dev-env-logs": "dist/bin/vip-dev-env-logs.js", + "vip-dev-env-purge": "dist/bin/vip-dev-env-purge.js", "vip-export": "dist/bin/vip-export.js", "vip-export-sql": "dist/bin/vip-export-sql.js", "vip-dev-env-sync": "dist/bin/vip-dev-env-sync.js", diff --git a/src/bin/vip-dev-env-purge.js b/src/bin/vip-dev-env-purge.js index b7c0cbf23..90dd39777 100644 --- a/src/bin/vip-dev-env-purge.js +++ b/src/bin/vip-dev-env-purge.js @@ -15,6 +15,7 @@ import { getEnvTrackingInfo, handleCLIException, validateDependencies, + promptForBoolean, } from '../lib/dev-environment/dev-environment-cli'; import { destroyEnvironment, @@ -30,10 +31,15 @@ const examples = [ usage: `${ DEV_ENVIRONMENT_FULL_COMMAND } purge`, description: 'Destroys all local dev environments', }, + { + usage: `${ DEV_ENVIRONMENT_FULL_COMMAND } purge --force`, + description: 'Destroys all local dev environments without prompting', + }, ]; command() .option( 'soft', 'Keep config files needed to start an environment intact' ) + .option( 'force', 'Removes prompt that verifies if user wants to destroy all environments' ) .examples( examples ) .argv( process.argv, async ( arg, opt ) => { const allEnvNames = getAllEnvironmentNames(); @@ -41,6 +47,22 @@ command() const trackingInfo = { all: true }; await trackEvent( 'dev_env_purge_command_execute', trackingInfo ); + if ( allEnvNames.length === 0 ) { + console.log( 'No environments to purge!' ); + return; + } + + if ( ! opt.force ) { + const purge = await promptForBoolean( + 'Are you sure you want to purge ALL existing dev environments?', + true + ); + + if ( ! purge ) { + return; + } + } + try { for ( const envName of allEnvNames ) { const slug = envName; diff --git a/src/bin/vip-dev-env.js b/src/bin/vip-dev-env.js index 32ddf75e4..fd65bd36f 100755 --- a/src/bin/vip-dev-env.js +++ b/src/bin/vip-dev-env.js @@ -20,4 +20,5 @@ command( { .command( 'shell', 'Spawns a shell in a dev environment' ) .command( 'logs', 'View logs from a local WordPress environment' ) .command( 'sync', 'Pull data from production to local development environment' ) + .command( 'purge', 'Destroy all existing environments' ) .argv( process.argv );