Skip to content

Commit

Permalink
Merge pull request #115 from woocommerce/update/cli-docs
Browse files Browse the repository at this point in the history
Update CLI command documentation for consistency
  • Loading branch information
coreymckrill authored Mar 14, 2023
2 parents c5dd9d1 + 813ac64 commit 2f38cda
Showing 1 changed file with 61 additions and 86 deletions.
147 changes: 61 additions & 86 deletions includes/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@ class CLI extends WP_CLI_Command {
/**
* Generate products.
*
* ## OPTIONS
*
* <amount>
* : The amount of products to generate
* ---
* default: 100
* ---
*
* ## EXAMPLES
* wc generate products 100
*
* @param array $args Arguments specified.
* @param array $assoc_args Associative arguments specified.
*/
public static function products( $args, $assoc_args ) {
list( $amount ) = $args;
$amount = absint( $amount );

$time_start = microtime( true );

Expand Down Expand Up @@ -59,30 +49,15 @@ public static function products( $args, $assoc_args ) {
/**
* Generate orders.
*
* ## OPTIONS
*
* <amount>
* : The amount of orders to generate
* ---
* default: 100
* ---
*
* ## EXAMPLES
* wc generate orders 100
*
* @param array $args Arguments specified.
* @param array $assoc_args Associative arguments specified.
*/
public static function orders( $args, $assoc_args ) {
list( $amount ) = $args;
$amount = absint( $amount );

$time_start = microtime( true );

$amount = (int) $amount;
if ( empty( $amount ) ) {
$amount = 100;
}

if ( ! empty( $assoc_args['status'] ) ) {
$status = $assoc_args['status'];
if ( ! wc_is_order_status( 'wc-' . $status ) ) {
Expand Down Expand Up @@ -111,22 +86,12 @@ public static function orders( $args, $assoc_args ) {
/**
* Generate customers.
*
* ## OPTIONS
*
* <amount>
* : The amount of customers to generate
* ---
* default: 100
* ---
*
* ## EXAMPLES
* wc generate customers 100
*
* @param array $args Arguments specified.
* @param array $assoc_args Associative arguments specified.
*/
public static function customers( $args, $assoc_args ) {
list( $amount ) = $args;
$amount = absint( $amount );

$time_start = microtime( true );

Expand All @@ -148,30 +113,15 @@ public static function customers( $args, $assoc_args ) {
/**
* Generate coupons.
*
* ## OPTIONS
*
* <amount>
* : The amount of coupons to generate
* ---
* default: 100
* ---
*
* ## EXAMPLES
* wc generate coupons 100
*
* @param array $args Arguments specified.
* @param array $assoc_args Associative arguments specified.
*/
public static function coupons( $args, $assoc_args ) {
list( $amount ) = $args;
$amount = absint( $amount );

$time_start = microtime( true );

$amount = (int) $amount;
if ( empty( $amount ) ) {
$amount = 10;
}

$min = 5;
$max = 100;
if ( ! empty( $assoc_args['min'] ) ) {
Expand Down Expand Up @@ -257,59 +207,84 @@ function () use ( $progress ) {
) );

WP_CLI::add_command( 'wc generate orders', array( 'WC\SmoothGenerator\CLI', 'orders' ), array(
'synopsis' => array(
'shortdesc' => 'Generate orders.',
'synopsis' => array(
array(
'name' => 'amount',
'type' => 'positional',
'optional' => true,
'default' => 100,
'name' => 'amount',
'type' => 'positional',
'description' => 'The number of orders to generate.',
'optional' => true,
'default' => 10,
),
array(
'name' => 'date-start',
'type' => 'assoc',
'optional' => true,
'name' => 'date-start',
'type' => 'assoc',
'description' => 'Randomize the order date using this as the lower limit. Format as YYYY-MM-DD.',
'optional' => true,
),
array(
'name' => 'date-end',
'type' => 'assoc',
'optional' => true,
'name' => 'date-end',
'type' => 'assoc',
'description' => 'Randomize the order date using this as the upper limit. Only works in conjunction with date-start. Format as YYYY-MM-DD.',
'optional' => true,
),
array(
'name' => 'status',
'type' => 'assoc',
'optional' => true,
'name' => 'status',
'type' => 'assoc',
'description' => 'Specify one status for all the generated orders. Otherwise defaults to a mix.',
'optional' => true,
'options' => array( 'completed', 'processing', 'on-hold', 'failed' ),
),
array(
'name' => 'coupons',
'type' => 'assoc',
'optional' => true,
'name' => 'coupons',
'type' => 'flag',
'description' => 'Create and apply a coupon to each generated order.',
'optional' => true,
),
),
'longdesc' => "## EXAMPLES\n\nwc generate orders 10\n\nwc generate orders 50 --date-start=2020-01-01 --date-end=2022-12-31 --status=completed --coupons",
) );

WP_CLI::add_command( 'wc generate customers', array( 'WC\SmoothGenerator\CLI', 'customers' ) );
WP_CLI::add_command( 'wc generate customers', array( 'WC\SmoothGenerator\CLI', 'customers' ), array(
'shortdesc' => 'Generate customers.',
'synopsis' => array(
array(
'name' => 'amount',
'type' => 'positional',
'description' => 'The number of customers to generate.',
'optional' => true,
'default' => 10,
),
),
'longdesc' => "## EXAMPLES\n\nwc generate customers 10",
) );

WP_CLI::add_command( 'wc generate coupons', array( 'WC\SmoothGenerator\CLI', 'coupons' ), array(
'synopsis' => array(
'shortdesc' => 'Generate coupons.',
'synopsis' => array(
array(
'name' => 'amount',
'type' => 'positional',
'optional' => true,
'default' => 10,
'name' => 'amount',
'type' => 'positional',
'description' => 'The number of coupons to generate.',
'optional' => true,
'default' => 10,
),
array(
'name' => 'min',
'optional' => true,
'type' => 'assoc',
'default' => 5,
'name' => 'min',
'type' => 'assoc',
'description' => 'Specify the minimum discount of each coupon.',
'optional' => true,
'default' => 5,
),
array(
'name' => 'max',
'optional' => true,
'type' => 'assoc',
'default' => 100,
'name' => 'max',
'type' => 'assoc',
'description' => 'Specify the maximum discount of each coupon.',
'optional' => true,
'default' => 100,
),
),
'longdesc' => "## EXAMPLES\n\nwc generate coupons 10\n\nwc generate coupons 50 --min=1 --max=50",
) );

WP_CLI::add_command( 'wc generate terms', array( 'WC\SmoothGenerator\CLI', 'terms' ), array(
Expand Down Expand Up @@ -344,5 +319,5 @@ function () use ( $progress ) {
'default' => 0,
),
),
'longdesc' => "## EXAMPLES\n\nwc generate terms product_tag 10\n\nwc generate terms product_cat 50 --max_depth=3",
'longdesc' => "## EXAMPLES\n\nwc generate terms product_tag 10\n\nwc generate terms product_cat 50 --max-depth=3",
) );

0 comments on commit 2f38cda

Please sign in to comment.