CLI_Command::has_command()
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. $ wp cli has-command "site delete" $ echo $? 0
# The "foo bar" command is not registered. $ wp cli has-command "foo bar" $ echo $? 1
Method of the class: CLI_Command{}
No Hooks.
Return
null
. Nothing (null).
Usage
$CLI_Command = new CLI_Command(); $CLI_Command->has_command( $_, $assoc_args );
- $_ (required)
- -
- $assoc_args (required)
- -
CLI_Command::has_command() CLI Command::has command code WP-CLI 2.8.0-alpha
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 ); }