OSDN Git Service

Ensure `wp plugin delete` and `wp theme delete` output consistent messages.
authorscribu <mail@scribu.net>
Tue, 4 Jun 2013 14:26:33 +0000 (17:26 +0300)
committerscribu <mail@scribu.net>
Tue, 4 Jun 2013 14:36:17 +0000 (17:36 +0300)
features/plugin.feature
features/upgradables.feature
php/commands/plugin.php
php/commands/theme.php

index 5ab7873..174ab4a 100644 (file)
@@ -37,13 +37,26 @@ Feature: Manage WordPress plugins
       | name       | status | update | version   |
       | zombieland | active | none   | 0.1-alpha |
 
-    When I run `wp plugin delete zombieland`
-    Then the {PLUGIN_DIR}/zombieland file should not exist
-
-    When I try `wp plugin status zombieland`
+    When I try `wp plugin uninstall zombieland`
     Then the return code should be 1
     And STDERR should contain:
       """
-      Error: The plugin 'zombieland' could not be found.
+      The plugin is active.
       """
 
+    When I run `wp plugin deactivate zombieland`
+    Then STDOUT should not be empty
+
+    When I run `wp plugin uninstall zombieland`
+    Then STDOUT should contain:
+      """
+      Success: Uninstalled 'zombieland' plugin.
+      """
+    And the {PLUGIN_DIR}/zombieland file should not exist
+
+    When I try the previous command again
+    Then the return code should be 1
+    And STDERR should contain:
+      """
+      The plugin 'zombieland' could not be found.
+      """
index 0dd81ef..e444286 100644 (file)
@@ -1,6 +1,6 @@
 Feature: Manage WordPress themes and plugins
 
-  Scenario Outline: Upgrading a theme or plugin
+  Scenario Outline: Installing, upgrading and deleting a theme or plugin
     Given a WP install
     And I run `wp <type> install <item> --version=<version>`
 
@@ -13,7 +13,8 @@ Feature: Manage WordPress themes and plugins
     When I run `wp <type> status <item>`
     Then STDOUT should contain:
       """
-      Version: <version> (Update available)
+          Status: Inactive
+          Version: <version> (Update available)
       """
 
     When I run `wp <type> update <item>`
@@ -25,6 +26,16 @@ Feature: Manage WordPress themes and plugins
       (Update available)
       """
 
+    When I run `wp <type> delete <item>`
+    Then STDOUT should contain:
+      """
+      Success: Deleted '<item>' <type>.
+      """
+
+    When I try `wp <type> status <item>`
+    Then the return code should be 1
+    And STDERR should not be empty
+
     Examples:
       | type   | item                    | version |
       | theme  | p2                      | 1.0.1   |
index 6d6f120..4b860a0 100644 (file)
@@ -192,12 +192,12 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
         * @synopsis <plugin> [--version=<version>]
         */
        function update( $args, $assoc_args ) {
+               list( $basename ) = $this->parse_name( $args );
+
                if ( isset( $assoc_args['version'] ) && 'dev' == $assoc_args['version'] ) {
-                       $this->delete( $args, array(), false );
+                       $this->_delete( $basename, false );
                        $this->install( $args, $assoc_args );
                } else {
-                       list( $basename ) = $this->parse_name( $args );
-
                        $was_active = is_plugin_active( $basename );
                        $was_network_active = is_plugin_active_for_network( $basename );
 
@@ -264,8 +264,12 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
 
                uninstall_plugin( $file );
 
-               if ( !isset( $assoc_args['no-delete'] ) )
-                       $this->delete( $args );
+               if ( isset( $assoc_args['no-delete'] ) )
+                       return;
+
+               if ( $this->_delete( $file ) ) {
+                       WP_CLI::success( sprintf( "Uninstalled '%s' plugin.", $name ) );
+               }
        }
 
        /**
@@ -273,16 +277,12 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
         *
         * @synopsis <plugin>
         */
-       function delete( $args, $assoc_args = array(), $exit_on_error = true ) {
+       function delete( $args, $assoc_args = array() ) {
                list( $file, $name ) = $this->parse_name( $args );
 
-               $plugin_dir = dirname( $file );
-               if ( '.' == $plugin_dir )
-                       $plugin_dir = $file;
-
-               $command = 'rm -rf ' . path_join( WP_PLUGIN_DIR, $plugin_dir );
-
-               return WP_CLI::launch( $command, $exit_on_error );
+               if ( $this->_delete( $file ) ) {
+                       WP_CLI::success( sprintf( "Deleted '%s' plugin.", $name ) );
+               }
        }
 
        /**
@@ -362,6 +362,16 @@ class Plugin_Command extends \WP_CLI\CommandWithUpgrade {
 
                return $name;
        }
+
+       private function _delete( $file ) {
+               $plugin_dir = dirname( $file );
+               if ( '.' == $plugin_dir )
+                       $plugin_dir = $file;
+
+               $command = 'rm -rf ' . path_join( WP_PLUGIN_DIR, $plugin_dir );
+
+               return ! WP_CLI::launch( $command );
+       }
 }
 
 WP_CLI::add_command( 'plugin', 'Plugin_Command' );
index 4aceba9..50245e7 100644 (file)
@@ -189,18 +189,19 @@ class Theme_Command extends \WP_CLI\CommandWithUpgrade {
         */
        function delete( $args ) {
                $theme = $this->parse_name( $args );
+               $theme_slug = $theme->get_stylesheet();
 
                if ( $this->is_active_theme( $theme ) ) {
                        WP_CLI::error( "Can't delete the currently active theme." );
                }
 
-               $r = delete_theme( $theme->get_stylesheet() );
+               $r = delete_theme( $theme_slug );
 
                if ( is_wp_error( $r ) ) {
                        WP_CLI::error( $r );
                }
 
-               WP_CLI::success( "$theme->name theme deleted." );
+               WP_CLI::success( sprintf( "Deleted '%s' theme.", $theme_slug ) );
        }
 
        /**