Add restart command and --watch option to wp shell
- [x] Understand current codebase structure and how REPL works
- [x] Implement restart functionality in REPL class
- [x] Add special command detection for 'restart'
- [x] Return special exit code (10) when restart is requested
- [x] Update REPL loop to return instead of infinite loop on restart
- [x] Add 'exit' command support for clean exit
- [x] Implement wrapper loop in Shell_Command to restart REPL
- [x] Check return value and restart if needed
- [x] Handle restart loop with do-while pattern
- [x] Add comprehensive tests for restart and exit functionality
- [x] Implement --watch option for auto-restart on file changes
- [x] Add --watch parameter handling with validation
- [x] Add file modification time tracking
- [x] Implement recursive directory monitoring
- [x] Auto-restart when changes detected
- [x] Force --basic mode when --watch is used
- [x] Update documentation in docblocks with examples
- [x] Run code review (passed with no issues)
- [x] Run security checks (no issues found)
- [x] Fix PHPCS alignment issues
- [x] Remove unnecessary PHPStan ignore directive
- [x] Add SplFileInfo type hint for PHPStan
Implementation Complete
All requirements from the issue have been implemented and code style issues have been addressed.
Original prompt
This section details on the original issue you should resolve
<issue_title>Support restarting a shell</issue_title> <issue_description>The
wp shellcommand is super useful for debugging sessions, however it is quite tedious when you need to make code changes, as it does not reload the modified code.By properly spawning the actual REPL in a new PHP process, and by checking the exit state for a specific result, it should be possible to inject a command that allows for restarting the REPL.
Bonus points: provide a
wp shell --watch=<folder>command that watches for changes in a specific folder and restarts the shell automatically.</issue_description>Comments on the Issue (you are @copilot in this section)
@danielbachhuber 💯
- Fixes wp-cli/shell-command#76
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Codecov Report
:x: Patch coverage is 26.00000% with 37 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/WP_CLI/Shell/REPL.php | 18.75% | 26 Missing :warning: |
| src/Shell_Command.php | 38.88% | 11 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!
@copilot Please fix the PHPCS issues ("Equals sign not aligned with surrounding assignments") and verify with composer phpcs. You can also use composer phpcbf to format the code.
Also, seems like that @phpstan-ignore while.alwaysTrue directive is no longer needed and can be removed.
Might need to cast $file as SplFileInfo via PHPDoc, otherwise PHPStan reports "Cannot call method getMTime() on mixed"
@copilot Please fix the PHPCS issues ("Equals sign not aligned with surrounding assignments") and verify with
composer phpcs. You can also usecomposer phpcbfto format the code.Also, seems li...
Fixed in f502d3d:
- Aligned equals signs in
get_recursive_mtime()method - Removed the
@phpstan-ignore while.alwaysTruedirective (no longer needed since the loop can now return) - Added
@var \SplFileInfo $filePHPDoc cast to resolve PHPStan warning aboutgetMTime()on mixed type