-
Notifications
You must be signed in to change notification settings - Fork 974
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
Introduce wp cli has-command
to detect whether a command is registered
#4349
Changes from 10 commits
cbb3450
030f7e7
967dd89
a5adcb7
aa619e6
4a48a48
ac0cb85
4142212
f99a682
35965c1
851c98f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,4 +575,38 @@ private function get_update_type_str( $assoc_args ) { | |
return $update_type; | ||
} | ||
|
||
/** | ||
* Detects if a command exists | ||
* | ||
* This commands checks if a command is registered with WP-CLI. | ||
* If the command is found then it returns with exit status 0. | ||
* If the command doesn't exist, then it will exit with status 1. | ||
* | ||
* ## OPTIONS | ||
* <command_name>... | ||
* : The command | ||
* | ||
* ## EXAMPLES | ||
* | ||
* The "site delete" command is registered. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the examples, you should follow the notation convention, as @danielbachhuber had provided: Comments start with Here's one example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a link to the documentation for this: https://make.wordpress.org/cli/handbook/documentation-standards/#command-annotation |
||
* $ wp cli has-command "site delete" | ||
* $ echo $? | ||
* 0 | ||
* | ||
* The "foo bar" command is not registered. | ||
* $ wp cli has-command "foo bar" | ||
* $ echo $? | ||
* 1 | ||
* | ||
* @subcommand has-command | ||
* | ||
* @when after_wp_load | ||
*/ | ||
public function has_command( $_, $assoc_args ) { | ||
|
||
// If command is input as a string, then explode it into array. | ||
$command = explode( ' ', implode( ' ', $_ ) ); | ||
|
||
WP_CLI::halt( is_array( WP_CLI::get_runner()->find_command_to_run( $command ) ) ? 0 : 1 ); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs another space after this heading.