OSDN Git Service

Create `get_api_for_version()`, which will give us the proper download link for a...
authorDaniel Bachhuber <d@danielbachhuber.com>
Mon, 3 Jun 2013 17:34:22 +0000 (10:34 -0700)
committerDaniel Bachhuber <d@danielbachhuber.com>
Mon, 3 Jun 2013 17:34:22 +0000 (10:34 -0700)
php/WP_CLI/CommandWithUpgrade.php
php/commands/theme.php

index d2b8529..bed5291 100644 (file)
@@ -119,6 +119,32 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {
                }
        }
 
+       protected function get_api_for_version( $api, $version ) {
+               
+               list( $link ) = explode( $api->slug, $api->download_link );
+
+               if ( stripos( $api->download_link, 'theme' ) )
+                       $download_type = 'theme';
+               else
+                       $download_type = 'plugin';
+
+
+               if ( 'dev' == $version ) {
+                       $api->download_link = $link . $api->slug . '.zip';
+                       $api->version = 'Development Version';
+               } else {
+                       $api->download_link = $link . $api->slug . '.' . $version .'.zip';
+                       $api->version = $version;
+
+                       // check if the requested version exists
+                       $response = wp_remote_head( $api->download_link );
+                       if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
+                               \WP_CLI::error( sprintf( "Can't find the requested %s's version %s in the WordPress.org %s repository.", $download_type, $version, $download_type ) );
+                               }
+               }
+               return $api;
+       }
+
        protected function _update( $item ) {
                call_user_func( $this->upgrade_refresh );
 
index 3b0a5c6..4c54147 100644 (file)
@@ -107,6 +107,9 @@ class Theme_Command extends \WP_CLI\CommandWithUpgrade {
                                WP_CLI::error( $api );
                }
 
+               if ( ! empty( $assoc_args['version'] ) )
+                       $api = $this->get_api_for_version( $api, $assoc_args['version'] );
+
                // Check to see if we should update, rather than install.
                if ( $this->has_update( $slug ) ) {
                        WP_CLI::line( sprintf( 'Updating %s (%s)', $api->name, $api->version ) );