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
I'm working on a new set of commands for a project and each one has a set of common parameters that can be used. For example, I may or may not want a progress bar on each one of these commands, such as:
* [--[no-]progress-bar]
* : Show a progress bar (default) or show each individual post as it's generated
As of right now, I have to copy/paste this into the OPTIONS and synopsis section of the PHPDoc comments of each new command I'm creating. Is there a way to define a list of common command parameters and then be able to reference them when creating a new subcommand? I already built a parse_common_args() method in my code to process the common parameters, but I'm not sure if it's possible to define or import these in the PHPDoc comments.
The text was updated successfully, but these errors were encountered:
Is there a way to define a list of common command parameters and then be able to reference them when creating a new subcommand?
In v0.23.0 (and already in the nightly), WP-CLI will support registering command synopsis in WP_CLI::add_command()'s third argument. Here's an example:
function foo( $args ) {
$message = array_shift( $args );
WP_CLI::log( 'Message is: ' . $message );
WP_CLI::success( $args[0] );
}
WP_CLI::add_command( 'foo', 'foo', array(
'shortdesc' => 'My awesome function command',
'when' => 'before_wp_load',
'synopsis' => array(
array(
'type' => 'positional',
'name' => 'message',
'description' => 'An awesome message to display',
'optional' => false,
),
array(
'type' => 'assoc',
'name' => 'apple',
'description' => 'A type of fruit.',
'optional' => false,
),
array(
'type' => 'assoc',
'name' => 'meal',
'description' => 'A type of meal.',
'optional' => true,
),
),
) );
You can assign your arguments to a variable, and then reuse the variable between command registration.
I'm working on a new set of commands for a project and each one has a set of common parameters that can be used. For example, I may or may not want a progress bar on each one of these commands, such as:
As of right now, I have to copy/paste this into the OPTIONS and synopsis section of the PHPDoc comments of each new command I'm creating. Is there a way to define a list of common command parameters and then be able to reference them when creating a new subcommand? I already built a parse_common_args() method in my code to process the common parameters, but I'm not sure if it's possible to define or import these in the PHPDoc comments.
The text was updated successfully, but these errors were encountered: