| 1 |
<?php |
| 2 |
/** |
| 3 |
* CLI_Manager — registers a module's WP-CLI commands under the |
| 4 |
* `wp xspeed <module> ...` namespace. |
| 5 |
* |
| 6 |
* Loaded only when WP_CLI is defined and truthy (Module_Registry guards |
| 7 |
* the call). Modules declare commands via Module::cli_commands(). |
| 8 |
* |
| 9 |
* The full xSpeed CLI surface is enumerated in FEATURES.md → "xSpeed CLI" |
| 10 |
* section (24 planned commands across all modules). Each handler shares |
| 11 |
* its core function with the matching REST callback — no duplicated |
| 12 |
* validation paths. |
| 13 |
* |
| 14 |
* @package XSpeed |
| 15 |
*/ |
| 16 |
|
| 17 |
namespace XSpeed; |
| 18 |
|
| 19 |
defined( 'ABSPATH' ) || exit; |
| 20 |
|
| 21 |
final class Cli_Manager { |
| 22 |
|
| 23 |
public static function register_module( Module $module ): void { |
| 24 |
if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
foreach ( $module->cli_commands() as $cmd ) { |
| 28 |
$name = $cmd['name'] ?? ''; |
| 29 |
$callback = $cmd['callback'] ?? null; |
| 30 |
if ( '' === $name || ! is_callable( $callback ) ) { |
| 31 |
continue; |
| 32 |
} |
| 33 |
$args = array(); |
| 34 |
if ( isset( $cmd['synopsis'] ) ) { |
| 35 |
$args['synopsis'] = $cmd['synopsis']; |
| 36 |
} |
| 37 |
if ( isset( $cmd['shortdesc'] ) ) { |
| 38 |
$args['shortdesc'] = $cmd['shortdesc']; |
| 39 |
} |
| 40 |
\WP_CLI::add_command( $name, $callback, $args ); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|