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 4 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,37 @@ 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 | ||
* wp cli has-command "wp site delete" | ||
* wp cli has-command wp site delete | ||
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. Each of these examples should have some explanation:
|
||
* | ||
* @subcommand has-command | ||
* | ||
* @when after_wp_load | ||
* | ||
* @param array $_ Array of positional arguments. | ||
* @param array $assoc_args Array of associative arguments. | ||
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. We should remove this argument definition, as it's not a pattern we have elsewhere. |
||
*/ | ||
public function has_command( $_, $assoc_args ) { | ||
|
||
// If command is input as a string, then explode it into array. | ||
$command = explode( ' ', implode( ' ', $_ ) ); | ||
|
||
if ( 'wp' === $command[0] ) { | ||
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. I don't think we should accept "wp" to this command. |
||
array_shift( $command ); | ||
} | ||
|
||
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.