Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CLI | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| list | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WP-CLI surface for the Feature Catalog. |
| 4 | * |
| 5 | * @package automattic/jetpack-features |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Features; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit( 0 ); |
| 12 | } |
| 13 | if ( ! class_exists( 'WP_CLI_Command' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | use WP_CLI; |
| 18 | use WP_CLI_Command; |
| 19 | |
| 20 | /** |
| 21 | * Inspect the feature catalog. |
| 22 | */ |
| 23 | class CLI extends WP_CLI_Command { |
| 24 | |
| 25 | /** |
| 26 | * List all registered features with their resolved status. |
| 27 | * |
| 28 | * ## EXAMPLES |
| 29 | * |
| 30 | * wp jetpack features list |
| 31 | * |
| 32 | * @subcommand list |
| 33 | * |
| 34 | * @param array $args Positional args. |
| 35 | * @param array $assoc_args Flags. |
| 36 | */ |
| 37 | public function list( $args, $assoc_args ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 38 | Features::ensure_registered(); |
| 39 | $registry = Registry::instance(); |
| 40 | $env = $registry->environment(); |
| 41 | if ( null === $env ) { |
| 42 | WP_CLI::error( 'No feature environment is bound.' ); |
| 43 | return; |
| 44 | } |
| 45 | $resolver = new Status_Resolver(); |
| 46 | $rows = array(); |
| 47 | foreach ( $registry->all() as $feature ) { |
| 48 | $r = $resolver->resolve( $feature, $env ); |
| 49 | $rows[] = array( |
| 50 | 'slug' => $feature->slug(), |
| 51 | 'status' => $r['status'], |
| 52 | 'reason' => $r['reason'], |
| 53 | 'connection' => $feature->required_connection(), |
| 54 | 'entitlement' => (string) $feature->required_entitlement(), |
| 55 | ); |
| 56 | } |
| 57 | if ( empty( $rows ) ) { |
| 58 | WP_CLI::warning( 'No features registered.' ); |
| 59 | return; |
| 60 | } |
| 61 | WP_CLI\Utils\format_items( 'table', $rows, array( 'slug', 'status', 'reason', 'connection', 'entitlement' ) ); |
| 62 | } |
| 63 | } |