Add optional $newline parameter to WP_CLI::log() and WP_CLI::line()#6276
Merged
swissspidy merged 3 commits intomainfrom Mar 16, 2026
Merged
Add optional $newline parameter to WP_CLI::log() and WP_CLI::line()#6276swissspidy merged 3 commits intomainfrom
$newline parameter to WP_CLI::log() and WP_CLI::line()#6276swissspidy merged 3 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
… logger info() methods Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add option to omit trailing newline in output
Add optional Mar 15, 2026
$newline parameter to WP_CLI::log() and WP_CLI::line()
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends WP-CLI’s output/logging API to optionally omit the trailing newline, enabling inline/progress-style output while preserving existing default behavior.
Changes:
- Add optional
$newline = trueparameter toWP_CLI::log()and legacyWP_CLI::line(). - Update logger
info()API and implement conditional newline handling inLoggers\Regular. - Add tests covering
Regular::info()with and without newline.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/LoggingTest.php | Adds unit tests validating info() newline behavior. |
| php/class-wp-cli.php | Adds $newline to WP_CLI::log()/line() and passes it through to the logger. |
| php/WP_CLI/Loggers/Regular.php | Implements conditional newline appending for info(). |
| php/WP_CLI/Loggers/Quiet.php | Updates info() signature for compatibility (still no-op). |
| php/WP_CLI/Loggers/Base.php | Updates abstract info() signature to include $newline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
swissspidy
approved these changes
Mar 16, 2026
swissspidy
added a commit
to apermo/wp-cli
that referenced
this pull request
Mar 16, 2026
…e()` (wp-cli#6276) * Initial plan * Add optional $newline parameter to WP_CLI::log(), WP_CLI::line(), and logger info() methods Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Undo Base class change --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
swissspidy
added a commit
that referenced
this pull request
Mar 16, 2026
…6270) * fix(context): resolve admin user dynamically Replace hardcoded user ID 1 fallback in Admin context with smart user resolution. On multisite, queries get_super_admins() to find a valid super admin. On single site, queries for the first user with the administrator role. Emits a clear error if no suitable user is found. Fixes #6269 * fix(context): optimize query and add test cases Use get_users() with login__in for single DB query instead of looping get_user_by(). Add single-site error case test. Replace wp super-admin commands with direct option manipulation in tests. * fix(context): fix linting issues Use single quotes for strings per PHPCS rules. Fix gherkin use-and lint violations by replacing consecutive When steps with And. * fix(context): address review feedback Revert multisite super admin lookup from get_users() back to foreach + get_user_by('login') loop because get_users() only fetches users on the current site but a super admin might not be a member of any site. Add debug logging after resolving admin user ID. * fix(context): use instanceof for type safety * Fix autoloader priority: locally installed packages now fully override phar-bundled versions (#6218) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Add environment variable configuration support to wp-cli.yml (#6169) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Autocomplete `--url` (#5704) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> * Add WP-CLI handbook link to `wp help` output (#6273) * Initial plan * Add WP-CLI handbook URL reference to wp help output Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Update file(s) from wp-cli/.github * Update file(s) from wp-cli/.github * Fix SSH alias path not forwarded to remote when defined as a separate config key (#6274) * Initial plan * Fix SSH alias path not forwarded to remote when path is a separate config key Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Fix: forward active alias to runcommand subprocess (#6272) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Fix vagrant SSH strict host key checking failure (#6275) * Initial plan * Fix vagrant SSH strict host key checking failure When ssh: vagrant is configured and vagrant ssh-config is parsed, add -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null to the SSH command to match what vagrant itself sets. This prevents failures when the vagrant VM has been recreated and has a different host key than what is stored in ~/.ssh/known_hosts. Adds a Behat test scenario to verify the fix. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @swissspidy --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Add optional `$newline` parameter to `WP_CLI::log()` and `WP_CLI::line()` (#6276) * Initial plan * Add optional $newline parameter to WP_CLI::log(), WP_CLI::line(), and logger info() methods Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Undo Base class change --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> * Refactor: remove unused imports (#6277) * Harden some tests on macOS * Update tests --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Ian Dunn <ian@iandunn.name> Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-authored-by: swissspidy <swissspidy@users.noreply.github.com> Co-authored-by: Sören Wünsch <soerenwrede@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The logging API always appended a newline to every message, making it impossible to implement inline progress patterns (e.g., print a prefix, do work, then append a result on the same line).
Changes
WP_CLI::log( $message, $newline = true )— new optional$newlineparameter passed through to the loggerWP_CLI::line( $message, $newline = true )— same treatment for the legacy aliasLoggers\Base::info()— updated abstract signature toinfo( $message, $newline = true )Loggers\Regular::info()— conditionally appends"\n"based on$newlineLoggers\Quiet::info()— updated signature for compatibility (still a no-op)Example
All changes are backwards-compatible —
$newlinedefaults totrue, preserving existing behaviour.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php(dns block)/usr/bin/php php vendor/bin/phpunit --color=always --filter LoggingTest --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php(dns block)nosuchhost_asdf_asdf_asdf.com/usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.