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 --quiet option to destroy command #68787

Open
wants to merge 4 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]
-q, --quiet Silence all non-error ouput and auto confirm choices [boolean] [default: false]
```

### `wp-env logs [environment]`
Expand Down
26 changes: 19 additions & 7 deletions packages/env/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ const wpYellow = boldWhite.bgHex( '#f0b849' );
const withSpinner =
( command ) =>
( ...args ) => {
const spinner = ora().start();
const quiet = args[ 0 ]?.quiet ?? false;
const spinner = ora();
if ( ! quiet ) {
spinner.start();
}
args[ 0 ].spinner = spinner;
let time = process.hrtime();
return command( ...args ).then(
( message ) => {
time = process.hrtime( time );
spinner.succeed(
`${ message || spinner.text } (in ${ time[ 0 ] }s ${ (
time[ 1 ] / 1e6
).toFixed( 0 ) }ms)`
);
if ( ! quiet ) {
time = process.hrtime( time );
spinner.succeed(
`${ message || spinner.text } (in ${ time[ 0 ] }s ${ (
time[ 1 ] / 1e6
).toFixed( 0 ) }ms)`
);
}
process.exit( 0 );
},
( error ) => {
Expand Down Expand Up @@ -244,6 +250,12 @@ module.exports = function cli() {
describe: 'Execute any configured lifecycle scripts.',
default: true,
} );
args.option( 'quiet', {
type: 'boolean',
alias: 'q',
describe: 'Supress non-error output and auto confirm',
default: false,
} );
},
withSpinner( env.destroy )
);
Expand Down
42 changes: 26 additions & 16 deletions packages/env/lib/commands/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const { executeLifecycleScript } = require( '../execute-lifecycle-script' );
* @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.quiet Supresses non-error output and auto confirms.
*/
module.exports = async function destroy( { spinner, scripts, debug } ) {
module.exports = async function destroy( { spinner, scripts, debug, quiet } ) {
const config = await loadConfig( path.resolve( '.' ) );

try {
Expand All @@ -36,25 +37,34 @@ module.exports = async function destroy( { spinner, scripts, debug } ) {
return;
}

spinner.info(
'WARNING! This will remove Docker containers, volumes, networks, and images associated with the WordPress instance.'
);
if ( ! quiet ) {
spinner.info(
'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 );
// If we are running in quiet mode we auto accept any confirmation.
let yesDelete = quiet;
if ( ! yesDelete ) {
try {
yesDelete = await confirm( {
message: 'Are you sure you want to continue?',
default: false,
} );
} catch ( error ) {
if ( error.name === 'ExitPromptError' ) {
if ( ! quiet ) {
console.log( 'Cancelled.' );
}
process.exit( 1 );
}
throw error;
}
throw error;
}

spinner.start();
if ( ! quiet ) {
spinner.start();
}

if ( ! yesDelete ) {
spinner.text = 'Cancelled.';
Expand Down
Loading