Pass in args to before_run_command hook#5554
Merged
schlessera merged 4 commits intowp-cli:masterfrom Sep 3, 2021
Merged
Conversation
CodeProKid
commented
Aug 11, 2021
| """ | ||
| And the return code should be 0 | ||
|
|
||
| Scenario: Add callback to the `before_run_command` with args |
Contributor
Author
There was a problem hiding this comment.
I'm definitely open to a better testing approach here to make sure the hook args are flowing through to the callback properly. 😆
Member
|
Love the fix, I'm always up for better hooks. I'm no expert on the behat tests, but now you only test the happy path not the 2 failure states. |
Contributor
Author
|
@schlessera curious if you have any thoughts/feedback on this change? |
Member
Those are already being tested by checking for the return code. Those 2 failure states use |
schlessera
requested changes
Sep 2, 2021
schlessera
approved these changes
Sep 3, 2021
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.
This PR passes in some args to the
before_run_commandhook so callbacks have some more context to base their logic off of.The reason for proposing this change is because of a particular use case I have where I'm implementing some logging to track CLI commands that are being run in our codebase. I currently have an implementation that looks something like:
This works for commands invoked from the command line but doesn't work for commands invoked via
WP_CLI::run_commandwithlaunch => falseset. This is becauserun_commandwill call theRunner->run_command()method directly so theRunnerinstance doesn't get bootstrapped again with the proper context.To get around this, I'm proposing we pass the params from the
run_commandmethod into thebefore_run_commandhook.