Created
June 21, 2019 14:57
-
-
Save JayWood/30f10428a26de7a2654d3e8bc7bb45da to your computer and use it in GitHub Desktop.
A live template for PHPStorm to create WP-CLI commands on-the-fly.
This file contains 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
namespace $var1$; | |
use Exception; | |
use WP_CLI; | |
class $class$ { | |
/** | |
* The WP-CLI Command Arguments | |
* | |
* Nothing to see here. | |
* | |
* @var array | |
*/ | |
private $args, $assoc_args; | |
/** | |
* Rather or not to do the actual import. | |
* @var bool | |
*/ | |
private $is_wet_run = false; | |
/** | |
* @var object Instance of the progress bar. | |
*/ | |
private $progress; | |
/** | |
* @param array $args | |
* @param array $assoc_args | |
* | |
* @throws WP_CLI\ExitException | |
*/ | |
public function __invoke( $args, $assoc_args ) { | |
// Properties so it can be reused later. | |
$this->args = $args; | |
$this->assoc_args = $assoc_args; | |
$this->is_wet_run = ! empty( $assoc_args['wet'] ); | |
} | |
} | |
try { | |
WP_CLI::add_command( '$command$', __NAMESPACE__ . '\\$class$', [ | |
'shortdesc' => '$description$', | |
'synopsis' => [ | |
[ | |
'type' => 'flag', | |
'name' => 'wet', | |
'optional' => true, | |
'description' => 'Actually runs the command.', | |
], | |
], | |
] ); | |
} catch ( Exception $e ) { | |
die( $e->getMessage() ); // @codingStandardsIgnoreLine Do not complain about escaping an exception. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment