@@ -182,7 +182,7 @@ public function package( $args, $assoc_args ) {
182
182
* ## OPTIONS
183
183
*
184
184
* <dir>
185
- * : Directory of an existing command .
185
+ * : Directory path to an existing package to generate a readme for .
186
186
*
187
187
* [--force]
188
188
* : Overwrite the readme if it already exists.
@@ -194,9 +194,7 @@ public function package_readme( $args, $assoc_args ) {
194
194
195
195
list ( $ package_dir ) = $ args ;
196
196
197
- if ( ! is_dir ( $ package_dir ) || ! file_exists ( $ package_dir . '/composer.json ' ) ) {
198
- WP_CLI ::error ( "Invalid package directory. composer.json file must be present. " );
199
- }
197
+ self ::check_if_valid_package_dir ( $ package_dir );
200
198
201
199
$ composer_obj = json_decode ( file_get_contents ( $ package_dir . '/composer.json ' ), true );
202
200
if ( ! $ composer_obj ) {
@@ -384,7 +382,7 @@ public function package_readme( $args, $assoc_args ) {
384
382
* ## OPTIONS
385
383
*
386
384
* <dir>
387
- * : The package directory to generate GitHub configuration for.
385
+ * : Directory path to an existing package to generate GitHub configuration for.
388
386
*
389
387
* [--force]
390
388
* : Overwrite files that already exist.
@@ -401,9 +399,8 @@ public function package_github( $args, $assoc_args ) {
401
399
$ package_dir = rtrim ( $ package_dir , '/ ' );
402
400
}
403
401
404
- if ( ! is_dir ( $ package_dir ) || ! file_exists ( $ package_dir . '/composer.json ' ) ) {
405
- WP_CLI ::error ( "Invalid package directory. composer.json file must be present. " );
406
- }
402
+ self ::check_if_valid_package_dir ( $ package_dir );
403
+
407
404
$ force = Utils \get_flag_value ( $ assoc_args , 'force ' );
408
405
$ template_path = dirname ( dirname ( __FILE__ ) ) . '/templates ' ;
409
406
@@ -492,7 +489,7 @@ public function package_github( $args, $assoc_args ) {
492
489
* ## OPTIONS
493
490
*
494
491
* <dir>
495
- * : The package directory to generate tests for.
492
+ * : Directory path to an existing package to generate tests for.
496
493
*
497
494
* [--ci=<provider>]
498
495
* : Create a configuration file for a specific CI provider.
@@ -522,9 +519,7 @@ public function package_tests( $args, $assoc_args ) {
522
519
$ package_dir = rtrim ( $ package_dir , '/ ' );
523
520
}
524
521
525
- if ( ! is_dir ( $ package_dir ) || ! file_exists ( $ package_dir . '/composer.json ' ) ) {
526
- WP_CLI ::error ( "Invalid package directory. composer.json file must be present. " );
527
- }
522
+ self ::check_if_valid_package_dir ( $ package_dir );
528
523
529
524
$ package_dir .= '/ ' ;
530
525
$ bin_dir = $ package_dir . 'bin/ ' ;
@@ -664,4 +659,14 @@ private function create_files( $files_and_contents, $force ) {
664
659
return $ wrote_files ;
665
660
}
666
661
662
+ private static function check_if_valid_package_dir ( $ package_dir ) {
663
+ if ( ! is_dir ( $ package_dir ) ) {
664
+ WP_CLI ::error ( 'Directory does not exist. ' );
665
+ }
666
+
667
+ if ( ! file_exists ( $ package_dir . '/composer.json ' ) ) {
668
+ WP_CLI ::error ( 'Invalid package directory. composer.json file must be present. ' );
669
+ }
670
+ }
671
+
667
672
}
0 commit comments