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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love adding a dependency on
WP_CLI::get_runner()inside of thisFormatterclass.My first thought was to add a new class-level
$in_colorvariable that can be passed when instantiated:However, this would just put the odd dependency elsewhere:
wp-cli/php/utils.php
Lines 362 to 369 in 9239cff
Because
Formatteralready callsWP_CLI::print_value(),Utils\write_csv(), etc., I think it's fine to call out toWP_CLI::or a utility function. We could add anin_color()method like this:We'd then use it like this:
This is all somewhat spaghetti logic, but I think what I propose is marginally better than calling
WP_CLI::get_runner()directly.Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber I agree that this dependency is not great. However, this has been one of the longstanding architectural issues that cannot easily be redressed, and references to the
WP_CLI::get_runner()are distributed all across the codebase. Therefore, I think it doesn't make sense to add additional spaghetti for this one instance when we cannot at the same time fix the bigger picture. I'd opt for keeping with theWP_CLI::get_runner()for now until we decide for a bigger rewrite.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlessera Ok, sounds good.