Skip to content

Commit c25b897

Browse files
committed
add deploy_cache delete WP-CLI cmd #31
1 parent 3c07537 commit c25b897

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ Success: Deployed to: zip in 00:00:01
121121
Sending confirmation email...
122122
```
123123

124+
Delete deploy cache
125+
126+
`wp statichtmloutput deploy_cache delete`
127+
128+
With option `--force`, else will prompt for confirmation.
129+
124130
## Hooks
125131

126132
### Modify the initial list of URLs to crawl

src/CLI.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,59 @@ public function options( $args, $assoc_args ) : void {
259259
);
260260
}
261261
}
262+
263+
/**
264+
* Deploy Cache
265+
*
266+
* <delete>
267+
*
268+
* Empty all URLs from DeployCache
269+
*
270+
* @param string[] $args Arguments after command
271+
* @param string[] $assoc_args Parameters after command
272+
*/
273+
public function deploy_cache( array $args, array $assoc_args ) : void {
274+
$action = isset( $args[0] ) ? $args[0] : null;
275+
276+
if ( empty( $action ) ) {
277+
WP_CLI::error(
278+
'Missing required argument: ' .
279+
'<delete>'
280+
);
281+
}
282+
283+
if ( $action === 'delete' ) {
284+
285+
if ( ! isset( $assoc_args['force'] ) ) {
286+
$this->multilinePrint(
287+
"no --force given. Please type 'yes' to confirm
288+
deletion of Deploy Cache"
289+
);
290+
291+
$userval = trim( (string) fgets( STDIN ) );
292+
293+
if ( $userval !== 'yes' ) {
294+
WP_CLI::error( 'Failed to delete Deploy Cache' );
295+
}
296+
}
297+
298+
$instance = Controller::getInstance();
299+
$instance->delete_deploy_cache();
300+
301+
WP_CLI::success( 'Deleted Deploy Cache' );
302+
}
303+
}
304+
305+
/**
306+
* Print multilines of input text via WP-CLI
307+
*/
308+
public function multilinePrint( string $string ) : void {
309+
$msg = trim( str_replace( [ "\r", "\n" ], '', $string ) );
310+
311+
$msg = preg_replace( '!\s+!', ' ', $msg );
312+
313+
WP_CLI::line( PHP_EOL . $msg . PHP_EOL );
314+
}
262315
}
263316

264317
/*

0 commit comments

Comments
 (0)