Cli
1 year ago
Exporters
1 year ago
Importers
11 months ago
ResourceStorages
1 year ago
ResultFormatters
1 year ago
Schemas
1 year ago
Steps
1 year ago
docs
1 year ago
BuiltInExporters.php
1 year ago
BuiltInStepProcessors.php
1 year ago
ClassExtractor.php
1 year ago
Cli.php
1 year ago
ExportSchema.php
1 year ago
ImportSchema.php
1 year ago
ImportStep.php
1 year ago
Logger.php
1 year ago
ResourceStorages.php
1 year ago
StepProcessor.php
1 year ago
StepProcessorResult.php
1 year ago
UsePluginHelpers.php
1 year ago
UsePubSub.php
1 year ago
UseWPFunctions.php
1 year ago
Util.php
1 year ago
Cli.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blueprint\Cli\ExportCli; |
| 6 | use Automattic\WooCommerce\Blueprint\Cli\ImportCli; |
| 7 | |
| 8 | $autoload_path = __DIR__ . '/../vendor/autoload.php'; |
| 9 | if ( file_exists( $autoload_path ) ) { |
| 10 | require_once $autoload_path; |
| 11 | } |
| 12 | /** |
| 13 | * Class Cli. |
| 14 | * |
| 15 | * This class is included and execute from WC_CLI(class-wc-cli.php) to register |
| 16 | * WP CLI commands. |
| 17 | */ |
| 18 | class Cli { |
| 19 | /** |
| 20 | * Register WP CLI commands. |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | public static function register_commands() { |
| 25 | \WP_CLI::add_command( |
| 26 | 'wc blueprint import', |
| 27 | function ( $args, $assoc_args ) { |
| 28 | $import = new ImportCli( $args[0] ); |
| 29 | $import->run( $assoc_args ); |
| 30 | }, |
| 31 | array( |
| 32 | 'synopsis' => array( |
| 33 | array( |
| 34 | 'type' => 'positional', |
| 35 | 'name' => 'schema-path', |
| 36 | 'optional' => false, |
| 37 | ), |
| 38 | array( |
| 39 | 'type' => 'assoc', |
| 40 | 'name' => 'show-messages', |
| 41 | 'optional' => true, |
| 42 | 'options' => array( 'all', 'error', 'info', 'debug' ), |
| 43 | ), |
| 44 | ), |
| 45 | 'when' => 'after_wp_load', |
| 46 | ) |
| 47 | ); |
| 48 | |
| 49 | \WP_CLI::add_command( |
| 50 | 'wc blueprint export', |
| 51 | function ( $args, $assoc_args ) { |
| 52 | $export = new ExportCli( $args[0] ); |
| 53 | $steps = array(); |
| 54 | |
| 55 | if ( isset( $assoc_args['steps'] ) ) { |
| 56 | $steps = array_map( |
| 57 | function ( $step ) { |
| 58 | return trim( $step ); |
| 59 | }, |
| 60 | explode( ',', $assoc_args['steps'] ) |
| 61 | ); |
| 62 | } |
| 63 | $export->run( |
| 64 | array( |
| 65 | 'steps' => $steps, |
| 66 | 'format' => 'json', |
| 67 | ) |
| 68 | ); |
| 69 | }, |
| 70 | array( |
| 71 | 'synopsis' => array( |
| 72 | array( |
| 73 | 'type' => 'positional', |
| 74 | 'name' => 'save-to', |
| 75 | 'optional' => false, |
| 76 | ), |
| 77 | array( |
| 78 | 'type' => 'assoc', |
| 79 | 'name' => 'steps', |
| 80 | 'optional' => true, |
| 81 | ), |
| 82 | ), |
| 83 | 'when' => 'after_wp_load', |
| 84 | ) |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 |