@@ -163,11 +163,18 @@ public function __invoke( $args, $assoc_args ) {
163163 $ php_only = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'precise ' );
164164 $ this ->recurse_objects = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'recurse-objects ' , true );
165165 $ this ->verbose = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'verbose ' );
166- $ this ->regex = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex ' );
167- $ this ->regex_flags = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-flags ' );
168- $ this ->regex_delimiter = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-delimiter ' , chr ( 1 ) );
169166 $ this ->format = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'format ' );
170167
168+ if ( ( $ this ->regex = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex ' , false ) ) ) {
169+ $ this ->regex_flags = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-flags ' , false );
170+ $ default_regex_delimiter = false ;
171+ $ this ->regex_delimiter = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'regex-delimiter ' , '' );
172+ if ( '' === $ this ->regex_delimiter ) {
173+ $ this ->regex_delimiter = chr ( 1 );
174+ $ default_regex_delimiter = true ;
175+ }
176+ }
177+
171178 if ( ! empty ( $ this ->regex ) ) {
172179 if ( '' === $ this ->regex_delimiter ) {
173180 $ this ->regex_delimiter = chr ( 1 );
@@ -177,7 +184,13 @@ public function __invoke( $args, $assoc_args ) {
177184 $ search_regex .= $ this ->regex_delimiter ;
178185 $ search_regex .= $ this ->regex_flags ;
179186 if ( false === @preg_match ( $ search_regex , '' ) ) {
180- \WP_CLI ::error ( "The regex ' $ search_regex' fails. " );
187+ if ( $ default_regex_delimiter ) {
188+ $ flags_msg = $ this ->regex_flags ? "flags ' $ this ->regex_flags ' " : "no flags " ;
189+ $ msg = "The regex pattern ' $ old' with default delimiter 'chr(1)' and {$ flags_msg } fails. " ;
190+ } else {
191+ $ msg = "The regex ' $ search_regex' fails. " ;
192+ }
193+ WP_CLI ::error ( $ msg );
181194 }
182195 }
183196
0 commit comments