Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command hooks mechanism for simple dependency resolution. #4033

Merged
merged 4 commits into from
May 1, 2017

Conversation

schlessera
Copy link
Member

@schlessera schlessera commented May 1, 2017

The following hooks have been added:

1. `before_add_command:<command>` - Called before WP_CLI tries to add the
command `<command>` to its known vocabulary.

The callback that is being called by this hook will receive an instance of
a `WP_CLI\Dispatcher\CommandAddition` object, which allows the callback to
control whether WP_CLI should proceed with the addition or not. On
aborting, the callback can provide a reason.

This can be used to let the addition of a command depend on some prior
requirement to be met.

2. `after_add_command:<command>` - Called after the command `<command>` has
been added to the known vocabulary.

This can be used for let the addition of the command depend on other
commands being added first. In this way, the addition of commands can be
rendered independent of loading order.

Note: Introducing the class `WP_CLI\Dispatcher\CommandAddition` was
necessary in order to get around the fact that arguments cannot be reliably
passed across the flow `do_hook()` -> `call_user_func_array()` ->
`add_hook()`.

Fixes #3835

The following hooks have been added:

1. `before_add_command:<command>` - Called before WP_CLI tries to add the command `<command>` to its known vocabulary.

The callback that is being called by this hook will receive an instance of a `WP_CLI\Dispatcher\CommandAddition` object, which allows the callback to control whether WP_CLI should proceed with the addition or not. On aborting, the callback can provide a reason.

This can be used to let the addition of a command depend on some prior requirement to be met.

2. `after_add_command:<command>` - Called after the command `<command>` has been added to the known vocabulary.

This can be used for let the addition of the command depend on other commands being added first. In this way, the addition of commands can be rendered independent of loading order.

Note: Introducing the class `WP_CLI\Dispatcher\CommandAddition` was necessary in order to get around the fact that arguments cannot be reliably passed across the flow `do_hook()` -> `call_user_func_array()` -> `add_hook()`.

Fixes #3835
The following hooks have been added:

1. `before_add_command:<command>` - Called before WP_CLI tries to add the command `<command>` to its known vocabulary.

The callback that is being called by this hook will receive an instance of a `WP_CLI\Dispatcher\CommandAddition` object, which allows the callback to control whether WP_CLI should proceed with the addition or not. On aborting, the callback can provide a reason.

This can be used to let the addition of a command depend on some prior requirement to be met.

2. `after_add_command:<command>` - Called after the command `<command>` has been added to the known vocabulary.

This can be used for let the addition of the command depend on other commands being added first. In this way, the addition of commands can be rendered independent of loading order.

Note: Introducing the class `WP_CLI\Dispatcher\CommandAddition` was necessary in order to get around the fact that arguments cannot be reliably passed across the flow `do_hook()` -> `call_user_func_array()` -> `add_hook()`.

Fixes #3835
@schlessera
Copy link
Member Author

Something weird going on with the commits (GitHub seemed to be out-of-sync).

This should be merged as one single squash commit.

@danielbachhuber danielbachhuber merged commit 7fcee0e into master May 1, 2017
@danielbachhuber danielbachhuber deleted the 3835-add-command-hooks branch May 1, 2017 18:04
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.

2 participants