Skip to content

Conversation

@ecairol
Copy link
Contributor

@ecairol ecairol commented Sep 8, 2025

Changes proposed

  • Swapped the order of 'site' and 'wp-cli-command' arguments for clarity.
  • This order makes more sense and also matches a similar command for WPCOM wpcom:run-site-wp-cli-command
  • Also made Site a mandatory value, instead of optional

How to reproduce issue

  • Open the Terminal
  • Run team51 pressable:run-site-wp-cli-command "https://mishtalk.com" "wp plugin list"
  • Notice how URL is first arguent and the WP command is the second argument
  • Expected: the WP is successfully executed on that site URL
  • Actual: OpsOasis receives the command wp+plugin+list as the Site ID: ❌ API error (404 https://opsoasis.wpspecialprojects.com/wp-json/wpcomsp/pressable/v1/sites/wp+plugin+list): {"code":"rest_no_route","message":"No route was found matching the URL and request method.","data":{"status":404}}

The command for WPCOM, wpcom:run-site-wp-cli-command, does take as the first argument the Site URL.

Summary by CodeRabbit

  • Refactor
    • Updated CLI command usage: now requires two arguments in this order—site (domain or ID) followed by the WP-CLI command.
    • Previously, the WP-CLI command came first and the site was optional.
    • Scripts or aliases using the old order will fail; update your usage to the new format.

- Swapped the order of 'site' and 'wp-cli-command' arguments for clarity.
- This order makes more sense and also matches a similar command for WPCOM wpcom:run-site-wp-cli-command
- Also made Site a mandatory value, instead of optional
@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

The CLI command WPCOMSpecialProjects\CLI\Command\Pressable_Site_WP_CLI_Command_Run updated its configure() method to change argument order and requirements. The first argument is now site (REQUIRED), followed by wp-cli-command (REQUIRED). Previously, wp-cli-command was REQUIRED and site was OPTIONAL. No other logic, error handling, or functionality changes are indicated.

Pre-merge checks (3 passed)

✅ Passed Checks (3 passed)
Check Name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change—reordering the arguments in the Pressable_Site_WP_CLI_Command_Run class—and directly reflects the main modification made in the changeset.
Description Check ✅ Passed The description provides clear context by outlining the proposed argument swap, matching behavior to an existing WPCOM command, and includes reproduction steps with expected versus actual outcomes, giving reviewers sufficient detail to understand and verify the change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  - Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
  - Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
✨ Finishing Touches
  • 📝 Generate Docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@ecairol ecairol requested a review from ahegyes September 8, 2025 22:24
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
commands/Pressable_Site_WP_CLI_Command_Run.php (3)

74-87: Warn when both --multiple and a single site are provided

Right now the provided site is silently ignored when --multiple is set. Emit a clear notice to avoid confusion.

Apply:

 protected function initialize( InputInterface $input, OutputInterface $output ): void {
   $this->skip_output = get_bool_input( $input, 'skip-output' );
   $this->multiple    = $input->getOption( 'multiple' );

-  if ( null === $this->multiple ) {
+  if ( null === $this->multiple ) {
     // If multiple is not set, treat it as a single site operation
     $site = get_pressable_site_input( $input, fn() => $this->prompt_site_input( $input, $output ) );
     $input->setArgument( 'site', $site );
     $this->sites = array( $site );
-  } elseif ( 'all' === $this->multiple ) {
+  } elseif ( 'all' === $this->multiple ) {
+    if ( $input->getArgument( 'site' ) ) {
+      $output->writeln( '<comment>--multiple provided; ignoring the single `site` argument.</comment>' );
+    }
     $this->sites = get_pressable_sites();
   } else {
+    if ( $input->getArgument( 'site' ) ) {
+      $output->writeln( '<comment>--multiple provided; ignoring the single `site` argument.</comment>' );
+    }
     $this->sites = $this->get_sites_from_multiple_input();
   }

89-95: Make ‘wp’ stripping safer

Pattern '/^wp/' can mangle commands starting with tokens like 'wpcom...'. Restrict to the standalone 'wp' token.

Apply:

-    $this->wp_command = \trim( \preg_replace( '/^wp/', '', \trim( $this->wp_command ) ) );
+    $this->wp_command = \trim( \preg_replace( '/^wp(\s+|$)/', '', \trim( $this->wp_command ) ) );

74-95: Optional: Back-compat shim for old argument order

To reduce breakage, auto-detect the old order and swap with a deprecation notice (grace period).

Apply near the start of initialize(), after reading $this->multiple:

// Back-compat: if multiple not set and the first arg looks like a WP-CLI command, swap.
if ( null === $this->multiple ) {
	$maybe_wp = (string) $input->getArgument( 'site' );
	if ( preg_match( '/^wp(\s+|$)|^(plugin|theme|option|user|post|search-replace)\b/', trim( $maybe_wp ) ) ) {
		$output->writeln( '<comment>Detected legacy argument order. Please use: site first, then command. (Swapping args for now.)</comment>' );
		$orig_cmd = $maybe_wp;
		$input->setArgument( 'site', get_pressable_site_input( $input, fn() => $this->prompt_site_input( $input, $output ) ) );
		$input->setArgument( 'wp-cli-command', $orig_cmd );
	}
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22f03b5 and 7743232.

📒 Files selected for processing (1)
  • commands/Pressable_Site_WP_CLI_Command_Run.php (1 hunks)

Comment on lines +64 to +65
$this->addArgument( 'site', InputArgument::REQUIRED, 'The domain or numeric Pressable ID of the site to open the shell to.' )
->addArgument( 'wp-cli-command', InputArgument::REQUIRED, 'The WP-CLI command to run.' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Argument reorder + site now REQUIRED — LGTM

Matches the PR objective and fixes the misrouting bug. This is a breaking CLI change; ensure docs/usages are updated.

Run to find and update usages/examples:


🏁 Script executed:

#!/usr/bin/env bash
# Find command invocations/usages to update argument order
rg -nC2 --pretty $'pressable:run-site-wp-cli-command\\b'
rg -nC2 --pretty $'wpcom:run-site-wp-cli-command\\b'

Length of output: 531


Update documentation and examples to reflect new argument order

Search for any external docs or example scripts referencing pressable:run-site-wp-cli-command or wpcom:run-site-wp-cli-command—internal code search only found the command definitions in commands/Pressable_Site_WP_CLI_Command_Run.php and commands/WPCOM_Site_WP_CLI_Command_Run.php. Ensure all user-facing documentation (READMEs, docs/cli guides, sample scripts) are updated so the site argument comes first.

🤖 Prompt for AI Agents
In commands/Pressable_Site_WP_CLI_Command_Run.php around lines 64-65, the
argument order was changed so the 'site' argument is now first but external
documentation and sample scripts may still show the old order; search the
repository for uses of pressable:run-site-wp-cli-command and
wpcom:run-site-wp-cli-command (README, docs/, sample scripts, CI scripts) and
update any examples and docs to list the arguments with 'site' first followed by
'wp-cli-command', ensuring any displayed command usage, help text, and example
invocations reflect the new order.

Comment on lines 67 to 68
$this->addOption( 'multiple', null, InputOption::VALUE_REQUIRED, 'Determines whether the `site` argument is optional or not. Accepted values are `all` or a comma-separated list of site IDs or domains.' )
->addOption( 'skip-output', null, InputOption::VALUE_NONE, 'Skip outputting the response to the console.' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update --multiple help text to reflect new semantics

It still says it “Determines whether the site argument is optional,” which is no longer true. Clarify that the site argument is ignored when --multiple is used.

Apply:

-        $this->addOption( 'multiple', null, InputOption::VALUE_REQUIRED, 'Determines whether the `site` argument is optional or not. Accepted values are `all` or a comma-separated list of site IDs or domains.' )
+        $this->addOption( 'multiple', null, InputOption::VALUE_REQUIRED, 'Run on multiple sites: `all` or a comma-separated list of site IDs/domains. When set, the single `site` argument is ignored.' )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$this->addOption( 'multiple', null, InputOption::VALUE_REQUIRED, 'Determines whether the `site` argument is optional or not. Accepted values are `all` or a comma-separated list of site IDs or domains.' )
->addOption( 'skip-output', null, InputOption::VALUE_NONE, 'Skip outputting the response to the console.' );
$this->addOption( 'multiple', null, InputOption::VALUE_REQUIRED, 'Run on multiple sites: `all` or a comma-separated list of site IDs/domains. When set, the single `site` argument is ignored.' )
->addOption( 'skip-output', null, InputOption::VALUE_NONE, 'Skip outputting the response to the console.' );
🤖 Prompt for AI Agents
In commands/Pressable_Site_WP_CLI_Command_Run.php around lines 67 to 68, the
--multiple option help text incorrectly states it "Determines whether the `site`
argument is optional"; update the option description to clarify that when
--multiple is used the `site` argument is ignored and to describe accepted
values (e.g. `all` or a comma-separated list of site IDs or domains), so the new
help text explicitly says the site argument is ignored when --multiple is
provided and lists the valid values.

@ahegyes
Copy link
Contributor

ahegyes commented Sep 9, 2025

The site value was optional because there should be a prompt for it 🤔 I think there was something that, if it's mandatory, it has to be provided and can't be added through the prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants