CLI_Alias_Command::is_group
Check whether an alias is a group.
OPTIONS
- <key>
- Key for the alias.
EXAMPLES
# Checks whether the alias is a group; exit status 0 if it is, otherwise 1. $ wp cli alias is-group @prod $ echo $? 1
Method of the class: CLI_Alias_Command{}
No Hooks.
Returns
null. Nothing (null).
Usage
$CLI_Alias_Command = new CLI_Alias_Command(); $CLI_Alias_Command->is_group( $args, $assoc_args );
- $args(required)
- .
- $assoc_args
- .
Default:array()
CLI_Alias_Command::is_group() CLI Alias Command::is group code WP-CLI 2.13.0-alpha
public function is_group( $args, $assoc_args = array() ) {
$alias = $args[0];
$aliases = WP_CLI::get_runner()->aliases;
if ( empty( $aliases[ $alias ] ) ) {
WP_CLI::error( "No alias found with key '{$alias}'." );
}
// how do we know the alias is a group?
// + array keys are numeric
// + array values begin with '@'
$first_item = $aliases[ $alias ];
$first_item_key = key( $first_item );
$first_item_value = $first_item[ $first_item_key ];
if ( is_numeric( $first_item_key ) && substr( $first_item_value, 0, 1 ) === '@' ) {
WP_CLI::halt( 0 );
}
WP_CLI::halt( 1 );
}