@@ -163,11 +163,18 @@ public function __invoke( $args, $assoc_args ) {
163
163
$ php_only = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'precise ' );
164
164
$ this ->recurse_objects = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'recurse-objects ' , true );
165
165
$ 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 ) );
169
166
$ this ->format = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'format ' );
170
167
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
+
171
178
if ( ! empty ( $ this ->regex ) ) {
172
179
if ( '' === $ this ->regex_delimiter ) {
173
180
$ this ->regex_delimiter = chr ( 1 );
@@ -177,7 +184,13 @@ public function __invoke( $args, $assoc_args ) {
177
184
$ search_regex .= $ this ->regex_delimiter ;
178
185
$ search_regex .= $ this ->regex_flags ;
179
186
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 );
181
194
}
182
195
}
183
196
0 commit comments