OSDN Git Service

Skip the iterator entirely
authorDaniel Bachhuber <d@danielbachhuber.com>
Fri, 22 Nov 2013 19:12:18 +0000 (11:12 -0800)
committerDaniel Bachhuber <d@danielbachhuber.com>
Fri, 22 Nov 2013 19:12:18 +0000 (11:12 -0800)
features/plugin.feature
php/WP_CLI/CommandWithUpgrade.php

index da76795..ecd3aab 100644 (file)
@@ -94,10 +94,10 @@ Feature: Manage WordPress plugins
     When I run `wp plugin activate akismet hello`
     Then STDOUT should not be empty
 
-    When I run `wp plugin list --status=inactive`
+    When I run `wp plugin list --status=inactive --field=name`
     Then STDOUT should be empty
 
-    When I run `wp plugin list --status=active`
+    When I run `wp plugin list --status=active --fields=name,status`
     Then STDOUT should be a table containing rows:
-      | name       | status   | update    | version   |
-      | akismet    | active   | available | 2.5.6     |
+      | name       | status   |
+      | akismet    | active   |
index 7ded309..1e931bf 100644 (file)
@@ -251,7 +251,8 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {
                if ( !is_array( $all_items ) )
                        \WP_CLI::error( "No {$this->item_type}s found." );
 
-               $it = \WP_CLI\Utils\iterator_map( $all_items, function( $item ) {
+               foreach( $all_items as $key => &$item ) {
+
                        if ( empty( $item['version'] ) )
                                $item['version'] = '';
 
@@ -263,23 +264,18 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {
                                }
                        }
 
-                       return $item;
-               } );
-
-               foreach( $it as $key => $item ) {
-
                        foreach( $this->obj_fields as $field ) {
 
                                if ( isset( $assoc_args[$field] )
                                        && $assoc_args[$field] != $item[$field] )
-                                       $it->offsetUnset( $key );
+                                       unset( $all_items[$key] );
 
                        }
 
                }
 
                $formatter = $this->get_formatter( $assoc_args );
-               $formatter->display_items( $it );
+               $formatter->display_items( $all_items );
        }
 
        /**