Simple class to create WP-CLI commands with validation with little effort.
- Create a WP CLI command by extending a simple class
- Easily hook into the command lifecycle by extending methods
before_run_command
,before_invoke
,after_invoke
- Advanced validation by extending method
validate
- Support for sub-commands by defining public methods
- Support for PHPDoc validation
- Require
wp-cli-command
in your project:composer require idearia/wp-cli-command
- Create a new command by extending the
Command
class. How? Have a look at the examples folder 🙂 - Register your command with
MyCommand::init( 'my-command' );
- Run the command with
wp my-command
.
In oder of execution:
before_run_command
> Just before the command is found and executedbefore_invoke
> Just before a command is invokedafter_invoke
> Just after a command is invoked
- A simple command from WP-CLI docs with an additional layer of validation: examples/SimpleCommand.php
- An example with two sub-commands, each with its own validation > TODO!
- 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.
- Behat tests with
wp scaffold package
- Example with subcommands
- Find a way to execute PHPDoc validation before custom validation (maybe invoking the command and the exiting with
before_invoke:{$cmd}
)? - Find a way to print actual usage, instead of relying on $usage property (how to force show_usage in subcommand.php)?