Skip to content

Warn when commands override global arguments#6174

Merged
swissspidy merged 16 commits intomainfrom
copilot/warn-on-global-argument-override
Mar 4, 2026
Merged

Warn when commands override global arguments#6174
swissspidy merged 16 commits intomainfrom
copilot/warn-on-global-argument-override

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 20, 2025

  • Explore repository structure and understand command registration flow
  • Identify config-spec.php as source of global arguments
  • Identify WP_CLI::add_command() in class-wp-cli.php as command registration point
  • Identify SynopsisParser for parsing command arguments
  • Implement global argument validation logic
  • Add validation during command registration
  • Add Behat tests for the warning functionality
  • Test the implementation manually
  • Verify linting, code style, and static analysis passes
  • Address code review feedback
  • Optimize with caching for better performance
  • Run security checks with codeql_checker
  • Fix issue with class-based commands bypassing validation
  • Add test for class-based command conflicts
  • Implement @skipglobalargcheck annotation to allow opt-out
  • Add test for skip annotation functionality
  • Improve warning message format
  • Enhance annotation detection to prevent false positives
  • Fix unit test failures by loading dispatcher.php earlier
  • Refactor to use public APIs instead of reflection
  • Fix test redirections and PHP 8.1+ compatibility
  • All changes complete and tested
Original prompt

This section details on the original issue you should resolve

<issue_title>Warn if overriding global argument</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

Right now, it's possible for custom commands to override global arguments such as debug or user, either accidentally or willingly.

This can make for confusing user experience because flags won't work as expected.

Plus, it makes it difficult to introduce new global arguments in the future because you won't know about it.

Describe the solution you'd like

If a command defines an argument with the same name as an existing global argument in WP-CLI, there should be a warning either when registering that command or when running the command.

Stretch goal:

This functionality could be used to more easily introduce new global arguments as well, by warning if an argument clashes with one we intend to introduce in the future. For example, in v3.0.0 we could warn you about using argument "foo", but only actually introduce it in v3.1.0, where it would error instead.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 20, 2025
Copilot AI and others added 3 commits December 20, 2025 19:50
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
… generic type

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add warning for overriding global arguments in commands Warn when commands override global arguments Dec 20, 2025
Copilot AI requested a review from swissspidy December 20, 2025 19:56
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 20, 2025

@swissspidy swissspidy marked this pull request as ready for review December 20, 2025 20:23
@swissspidy swissspidy requested a review from a team as a code owner December 20, 2025 20:23
@swissspidy swissspidy added this to the 3.0.0 milestone Jan 20, 2026
@swissspidy swissspidy requested a review from Copilot January 20, 2026 15:02

This comment was marked as resolved.

Check for global argument conflicts in CommandFactory::create_subcommand() to catch conflicts in class-based commands that bypass WP_CLI::add_command()

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Allows commands to opt-out of global argument conflict warnings by adding @skipglobalargcheck to their PHPdoc. This is useful for built-in commands that intentionally override global arguments.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Remove 'This can lead to unexpected behavior' from warning to match test expectations
- Use regex pattern matching for @skipglobalargcheck to prevent false positives
- Ensures annotation is only detected as an actual PHPDoc tag, not in description text

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Load dispatcher.php as part of LoadUtilityFunctions step
- Remove separate LoadDispatcher bootstrap step
- Add dispatcher.php to test bootstrap
- Resolves "Call to undefined function WP_CLI\Dispatcher\get_path()" error in unit tests

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

- Remove 2>&1 redirection from Behat tests
- Add public get_docparser() method to CompositeCommand
- Add public has_tag() method to DocParser for checking valueless tags
- Refactor command_skips_global_arg_check() to use public APIs
- Rename Subcommand's get_docparser() to create_mock_docparser() to avoid conflict
- Fixes PHP 8.1+ compatibility issue with reflection
- Improves code maintainability by using proper public APIs

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy merged commit abc7b86 into main Mar 4, 2026
67 of 68 checks passed
@swissspidy swissspidy deleted the copilot/warn-on-global-argument-override branch March 4, 2026 15:17
bonny added a commit to bonny/WordPress-Simple-History that referenced this pull request Mar 10, 2026
Avoids conflict with WP-CLI's global --user argument, which causes
warnings on newer WP-CLI versions (wp-cli/wp-cli#6174).

Adds functional test for --userid and --exclude_userid filters.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn if overriding global argument

3 participants