From 48c09dc6e02f64ba6dc24faa45ba8c3baecc06d4 Mon Sep 17 00:00:00 2001 From: JayWood Date: Sun, 13 Oct 2019 13:48:48 -0400 Subject: [PATCH] Package directives and move registration to main file. --- commands/class-cleanup.php | 53 ++------------ commands/class-generate.php | 101 ++------------------------ generate-posts.php | 141 ++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 140 deletions(-) diff --git a/commands/class-cleanup.php b/commands/class-cleanup.php index 06a541c..ed27981 100644 --- a/commands/class-cleanup.php +++ b/commands/class-cleanup.php @@ -1,8 +1,13 @@ '', - 'synopsis' => [ - [ - 'type' => 'assoc', - 'name' => 'type', - 'optional' => true, - 'description' => 'A comma separated list ( no spaces ) of post type slugs to cleanup.', - ], - [ - 'type' => 'flag', - 'name' => 'force-delete', - 'optional' => true, - 'default' => false, - 'description' => 'Forcefully deletes, skips the trash.', - ], - [ - 'type' => 'assoc', - 'name' => 'taxonomies', - 'optional' => true, - 'description' => 'A comma separated list ( no spacing ) of taxonomy slugs to cleanup.', - ], - [ - 'type' => 'assoc', - 'name' => 'post-author', - 'optional' => true, - 'description' => 'The post author ID, email or Login to cleanup posts for.', - 'default' => 1, - ], - [ - 'type' => 'assoc', - 'name' => 'post-status', - 'optional' => true, - 'description' => 'The post status to set the post to.', - ], - ], - ] ); -} catch ( Exception $e ) { - die( $e->getMessage() ); -} diff --git a/commands/class-generate.php b/commands/class-generate.php index 6e249ef..aa70ee3 100644 --- a/commands/class-generate.php +++ b/commands/class-generate.php @@ -1,8 +1,12 @@ faker->word; } } - -try { - WP_CLI::add_command( 'jw-random generate', __NAMESPACE__ . '\\Generate', [ - 'shortdesc' => 'Generates posts, terms and attachments based on options passed.', - 'synopsis' => [ - [ - 'type' => 'flag', - 'name' => 'wet', - 'optional' => true, - 'description' => 'Actually runs the command.', - ], - [ - 'type' => 'assoc', - 'name' => 'type', - 'optional' => true, - 'default' => 'post', - 'description' => 'A comma separated list ( no spaces ) of post type slugs to generate for.', - ], - [ - 'type' => 'flag', - 'name' => 'featured-image', - 'optional' => true, - 'default' => false, - 'description' => 'Enables featured image support ( see image types )', - ], - [ - 'type' => 'assoc', - 'optional' => true, - 'name' => 'image-size', - 'default' => '1024,768', - 'description' => 'A comma delimited width and height value for images to import.', - ], - [ - 'type' => 'assoc', - 'name' => 'image-type', - 'optional' => true, - 'description' => 'The type of featured images.', - 'default' => 'business', - 'options' => [ - 'abstract', - 'sports', - 'city', - 'people', - 'transport', - 'animals', - 'food', - 'nature', - 'business', - 'cats', - 'fashion', - 'nightlife', - 'fashion', - 'technics' - ], - ], - [ - 'type' => 'positional', - 'name' => 'num_posts', - 'optional' => true, - 'default' => 10, - 'description' => 'The number of posts to generate for each post type.', - ], - [ - 'type' => 'assoc', - 'name' => 'taxonomies', - 'optional' => true, - 'description' => 'A comma separated list ( no spacing ) of taxonomy slugs to generate terms for.', - ], - [ - 'type' => 'assoc', - 'name' => 'term-count', - 'optional' => true, - 'description' => 'The amount of terms to generate for each taxonomy slug. Terms are randomly assigned to posts.', - ], - [ - 'type' => 'assoc', - 'name' => 'post-author', - 'optional' => true, - 'description' => 'The post author ID, email or Login to assign the posts to.', - 'default' => 1, - ], - [ - 'type' => 'assoc', - 'name' => 'post-status', - 'optional' => true, - 'description' => 'The post status to set the post to.', - ], - ], - ] ); -} catch ( Exception $e ) { - die( $e->getMessage() ); // @codingStandardsIgnoreLine Do not complain about escaping an exception. -} - diff --git a/generate-posts.php b/generate-posts.php index 669bdce..27637f4 100644 --- a/generate-posts.php +++ b/generate-posts.php @@ -1,8 +1,149 @@ 'Generates posts, terms and attachments based on options passed.', + 'synopsis' => [ + [ + 'type' => 'flag', + 'name' => 'wet', + 'optional' => true, + 'description' => 'Actually runs the command.', + ], + [ + 'type' => 'assoc', + 'name' => 'type', + 'optional' => true, + 'default' => 'post', + 'description' => 'A comma separated list ( no spaces ) of post type slugs to generate for.', + ], + [ + 'type' => 'flag', + 'name' => 'featured-image', + 'optional' => true, + 'default' => false, + 'description' => 'Enables featured image support ( see image types )', + ], + [ + 'type' => 'assoc', + 'optional' => true, + 'name' => 'image-size', + 'default' => '1024,768', + 'description' => 'A comma delimited width and height value for images to import.', + ], + [ + 'type' => 'assoc', + 'name' => 'image-type', + 'optional' => true, + 'description' => 'The type of featured images.', + 'default' => 'business', + 'options' => [ + 'abstract', + 'sports', + 'city', + 'people', + 'transport', + 'animals', + 'food', + 'nature', + 'business', + 'cats', + 'fashion', + 'nightlife', + 'fashion', + 'technics' + ], + ], + [ + 'type' => 'positional', + 'name' => 'num_posts', + 'optional' => true, + 'default' => 10, + 'description' => 'The number of posts to generate for each post type.', + ], + [ + 'type' => 'assoc', + 'name' => 'taxonomies', + 'optional' => true, + 'description' => 'A comma separated list ( no spacing ) of taxonomy slugs to generate terms for.', + ], + [ + 'type' => 'assoc', + 'name' => 'term-count', + 'optional' => true, + 'description' => 'The amount of terms to generate for each taxonomy slug. Terms are randomly assigned to posts.', + ], + [ + 'type' => 'assoc', + 'name' => 'post-author', + 'optional' => true, + 'description' => 'The post author ID, email or Login to assign the posts to.', + 'default' => 1, + ], + [ + 'type' => 'assoc', + 'name' => 'post-status', + 'optional' => true, + 'description' => 'The post status to set the post to.', + ], + ], + ] ); + /* + * The Cleanup Command. + */ + WP_CLI::add_command( 'jw-random cleanup', __NAMESPACE__ . '\\Cleanup', [ + 'shortdesc' => '', + 'synopsis' => [ + [ + 'type' => 'assoc', + 'name' => 'type', + 'optional' => true, + 'description' => 'A comma separated list ( no spaces ) of post type slugs to cleanup.', + ], + [ + 'type' => 'flag', + 'name' => 'force-delete', + 'optional' => true, + 'default' => false, + 'description' => 'Forcefully deletes, skips the trash.', + ], + [ + 'type' => 'assoc', + 'name' => 'taxonomies', + 'optional' => true, + 'description' => 'A comma separated list ( no spacing ) of taxonomy slugs to cleanup.', + ], + [ + 'type' => 'assoc', + 'name' => 'post-author', + 'optional' => true, + 'description' => 'The post author ID, email or Login to cleanup posts for.', + 'default' => 1, + ], + [ + 'type' => 'assoc', + 'name' => 'post-status', + 'optional' => true, + 'description' => 'The post status to set the post to.', + ], + ], + ] ); + } catch ( Exception $e ) { + die( $e->getMessage() ); + } }