@@ -182,7 +182,7 @@ public function package( $args, $assoc_args ) {
182182 * ## OPTIONS
183183 *
184184 * <dir>
185- * : Directory of an existing command .
185+ * : Directory path to an existing package to generate a readme for .
186186 *
187187 * [--force]
188188 * : Overwrite the readme if it already exists.
@@ -194,9 +194,7 @@ public function package_readme( $args, $assoc_args ) {
194194
195195 list ( $ package_dir ) = $ args ;
196196
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 );
200198
201199 $ composer_obj = json_decode ( file_get_contents ( $ package_dir . '/composer.json ' ), true );
202200 if ( ! $ composer_obj ) {
@@ -384,7 +382,7 @@ public function package_readme( $args, $assoc_args ) {
384382 * ## OPTIONS
385383 *
386384 * <dir>
387- * : The package directory to generate GitHub configuration for.
385+ * : Directory path to an existing package to generate GitHub configuration for.
388386 *
389387 * [--force]
390388 * : Overwrite files that already exist.
@@ -401,9 +399,8 @@ public function package_github( $args, $assoc_args ) {
401399 $ package_dir = rtrim ( $ package_dir , '/ ' );
402400 }
403401
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+
407404 $ force = Utils \get_flag_value ( $ assoc_args , 'force ' );
408405 $ template_path = dirname ( dirname ( __FILE__ ) ) . '/templates ' ;
409406
@@ -492,7 +489,7 @@ public function package_github( $args, $assoc_args ) {
492489 * ## OPTIONS
493490 *
494491 * <dir>
495- * : The package directory to generate tests for.
492+ * : Directory path to an existing package to generate tests for.
496493 *
497494 * [--ci=<provider>]
498495 * : Create a configuration file for a specific CI provider.
@@ -522,9 +519,7 @@ public function package_tests( $args, $assoc_args ) {
522519 $ package_dir = rtrim ( $ package_dir , '/ ' );
523520 }
524521
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 );
528523
529524 $ package_dir .= '/ ' ;
530525 $ bin_dir = $ package_dir . 'bin/ ' ;
@@ -664,4 +659,14 @@ private function create_files( $files_and_contents, $force ) {
664659 return $ wrote_files ;
665660 }
666661
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+
667672}
0 commit comments