You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,10 @@ Simple class to create WP-CLI commands with validation with little effort.
2
2
3
3
# Features
4
4
5
-
- Create a command by extending a simple class
6
-
- Advanced validation
7
-
- Support for sub-commands
5
+
- Create a WP CLI command by extending a simple class
6
+
- Easily hook into the [command lifecycle](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-add-hook/#notes) by extending methods `before_run_command`, `before_invoke`, `after_invoke`
7
+
- Advanced validation by extending method `validate`
8
+
- Support for sub-commands by defining public methods
8
9
- Support for [PHPDoc validation](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/#annotating-with-phpdoc)
9
10
10
11
# Quick start
@@ -17,13 +18,22 @@ Simple class to create WP-CLI commands with validation with little effort.
17
18
3. Register your command with `MyCommand::init( 'my-command' );`
18
19
4. Run the command with `wp my-command`.
19
20
21
+
# Available hooks
22
+
23
+
In oder of execution:
24
+
25
+
-`before_run_command` > Just before the command is found and executed
26
+
-`before_invoke` > Just before a command is invoked
27
+
-`after_invoke` > Just after a command is invoked
28
+
20
29
# Example
21
30
22
31
- A simple command from [WP-CLI docs](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/#annotating-with-phpdoc) with an additional layer of validation: [examples/SimpleCommand.php](./examples/SimpleCommand.php)
23
32
- An example with two sub-commands, each with its own validation > TODO!
24
33
25
34
# To do
26
35
36
+
- Make hook methods aware of the specific command being executed, in case the class contains more than one. Probably, we will need to switch away from static, in order to save $args in the class.
27
37
- Behat tests with [`wp scaffold package`](https://github.com/wp-cli/scaffold-package-command)
28
38
- Example with subcommands
29
39
- Find a way to execute PHPDoc validation before custom validation (maybe invoking the command and the exiting with `before_invoke:{$cmd}`)?
0 commit comments