Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-env: Add --skip-confirmation option to destroy command #68787

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ Destroy the WordPress environment. Deletes docker containers, volumes, and
networks associated with the WordPress environment and removes local files.

Options:
--debug Enable debug output. [boolean] [default: false]
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
--debug Enable debug output. [boolean] [default: false]
--scripts Execute any configured lifecycle scripts. [boolean] [default: true]
--skip-confirmation Skip confirmation prompt. [boolean] [default: false]
```

### `wp-env logs [environment]`
Expand Down
5 changes: 5 additions & 0 deletions packages/env/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ module.exports = function cli() {
describe: 'Execute any configured lifecycle scripts.',
default: true,
} );
args.option( 'skip-confirmation', {
type: 'boolean',
describe: 'Skip confirmation prompt',
default: false,
} );
},
withSpinner( env.destroy )
);
Expand Down
38 changes: 23 additions & 15 deletions packages/env/lib/commands/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const { executeLifecycleScript } = require( '../execute-lifecycle-script' );
* Destroy the development server.
*
* @param {Object} options
* @param {Object} options.spinner A CLI spinner which indicates progress.
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
* @param {boolean} options.debug True if debug mode is enabled.
* @param {Object} options.spinner A CLI spinner which indicates progress.
* @param {boolean} options.scripts Indicates whether or not lifecycle scripts should be executed.
* @param {boolean} options.debug True if debug mode is enabled.
* @param {boolean} options.skip-confirmation Indicates whether or not to skip the confirmation prompt.
*/
module.exports = async function destroy( { spinner, scripts, debug } ) {
module.exports = async function destroy( {
spinner,
scripts,
debug,
'skip-confirmation': skipConfirmation,
} ) {
const config = await loadConfig( path.resolve( '.' ) );

try {
Expand All @@ -40,18 +46,20 @@ module.exports = async function destroy( { spinner, scripts, debug } ) {
'WARNING! This will remove Docker containers, volumes, networks, and images associated with the WordPress instance.'
);

let yesDelete = false;
try {
yesDelete = await confirm( {
message: 'Are you sure you want to continue?',
default: false,
} );
} catch ( error ) {
if ( error.name === 'ExitPromptError' ) {
console.log( 'Cancelled.' );
process.exit( 1 );
let yesDelete = skipConfirmation;
if ( ! yesDelete ) {
try {
yesDelete = await confirm( {
message: 'Are you sure you want to continue?',
default: false,
} );
} catch ( error ) {
if ( error.name === 'ExitPromptError' ) {
console.log( 'Cancelled.' );
process.exit( 1 );
}
throw error;
}
throw error;
}

spinner.start();
Expand Down
Loading