WP_CLI\Utils

get_flag_value()WP-CLI 1.0

Return the flag value or, if it's not set, the $default value.

Because flags can be negated (e.g. --no-quiet to negate --quiet), this function provides a safer alternative to using isset( $assoc_args['quiet'] ) or similar.

No Hooks.

Return

Mixed.

Usage

get_flag_value( $assoc_args, $flag, $default );
$assoc_args(array) (required)
Arguments array.
$flag(string) (required)
Flag to get the value.
$default(mixed)
Default value for the flag.
Default: NULL

Code of get_flag_value() WP-CLI 2.7.0-alpha

function get_flag_value( $assoc_args, $flag, $default = null ) {
	return isset( $assoc_args[ $flag ] ) ? $assoc_args[ $flag ] : $default;
}