From 1f0fea02edddfcfe816a8a73a1ba95a01ba7489e Mon Sep 17 00:00:00 2001 From: Soham Banerjee Date: Fri, 23 Oct 2026 19:07:57 +0530 Subject: [PATCH] Register WP-CLI subcommands under their documented hyphenated names WP-CLI names subcommands after the method unless @subcommand says otherwise, so 'wp rfsd purge-transients' (as documented in readme.txt and README.md) failed with 'not a registered subcommand'. The underscore names stay available as aliases. Co-Authored-By: Claude --- includes/class-rfsd-cli.php | 9 +++++++++ tests/php/test-cli.php | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/includes/class-rfsd-cli.php b/includes/class-rfsd-cli.php index 0335f51..92a05f4 100644 --- a/includes/class-rfsd-cli.php +++ b/includes/class-rfsd-cli.php @@ -24,6 +24,9 @@ class Rfsd_Cli { /** * Purge all cached FAQ output. * + * @subcommand purge-transients + * @alias purge_transients + * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ @@ -36,6 +39,9 @@ public function purge_transients( $args, $assoc_args ) { // phpcs:ignore Generic * Process invalidation queue via CLI. * Usage: wp rfsd process-queue --limit=1000 * + * @subcommand process-queue + * @alias process_queue + * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ @@ -49,6 +55,9 @@ public function process_queue( $args, $assoc_args ) { /** * Show queue length * + * @subcommand queue-info + * @alias queue_info + * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ diff --git a/tests/php/test-cli.php b/tests/php/test-cli.php index b7886d9..5e061e5 100644 --- a/tests/php/test-cli.php +++ b/tests/php/test-cli.php @@ -80,4 +80,28 @@ public function test_queue_info() { $this->cli->queue_info( array(), array() ); $this->assertSame( 'Queue length: 2', $this->last_success() ); } + + /** + * WP-CLI names a subcommand after its method unless @subcommand says otherwise; the readme documents the + * hyphenated names. + * + * @dataProvider subcommand_provider + * + * @param string $method Method name. + * @param string $subcommand Documented subcommand. + */ + public function test_subcommands_use_the_documented_names( $method, $subcommand ) { + $doc = ( new ReflectionMethod( 'RFSD\Rfsd_Cli', $method ) )->getDocComment(); + $this->assertStringContainsString( "@subcommand {$subcommand}\n", $doc ); + $this->assertStringContainsString( "@alias {$method}\n", $doc, 'The underscore name keeps working.' ); + $this->assertStringContainsString( "`wp rfsd {$subcommand}", file_get_contents( RFSD_PLUGIN_DIR . 'readme.txt' ) ); + } + + public function subcommand_provider() { + return array( + array( 'purge_transients', 'purge-transients' ), + array( 'process_queue', 'process-queue' ), + array( 'queue_info', 'queue-info' ), + ); + } }