OSDN Git Service

don't show progress bar if not in a TTY
authorscribu <mail@scribu.net>
Fri, 21 Jun 2013 13:02:24 +0000 (16:02 +0300)
committerscribu <mail@scribu.net>
Fri, 12 Jul 2013 00:53:58 +0000 (03:53 +0300)
this fixes 'tput: No value for $TERM and no -T specified' error

features/import.feature
php/WP_CLI/NoOp.php [new file with mode: 0644]
php/commands/post.php
php/commands/user.php
php/utils.php

index a10af31..e90d4c5 100644 (file)
@@ -2,13 +2,8 @@ Feature: Import content.
 
   Scenario: Basic export then import
     Given a WP install
-
-    When I run `wp post generate --post_type=post --count=3`
-    Then STDOUT should not be empty
-
-    When I run `wp post generate --post_type=page --count=2`
-    Then STDOUT should not be empty
-
+    And I run `wp post generate --post_type=post --count=3`
+    And I run `wp post generate --post_type=page --count=2`
     When I run `wp post list --post_type=any --format=count`
     Then STDOUT should be:
       """
diff --git a/php/WP_CLI/NoOp.php b/php/WP_CLI/NoOp.php
new file mode 100644 (file)
index 0000000..9334aff
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+namespace WP_CLI;
+
+final class NoOp {
+
+       function __set( $key, $value ) {
+               // do nothing
+       }
+
+       function __call( $method, $args ) {
+               // do nothing
+       }
+}
+
index 438f86a..d378366 100644 (file)
@@ -243,7 +243,7 @@ class Post_Command extends \WP_CLI\CommandWithDBObject {
 
                $limit = $count + $total;
 
-               $notify = new \cli\progress\Bar( 'Generating posts', $count );
+               $notify = \WP_CLI\Utils\make_progress_bar( 'Generating posts', $count );
 
                $current_depth = 1;
                $current_parent = 0;
index 3533ec8..59dccb4 100644 (file)
@@ -183,7 +183,7 @@ class User_Command extends \WP_CLI\CommandWithDBObject {
 
                $limit = $count + $total;
 
-               $notify = new \cli\progress\Bar( 'Generating users', $count );
+               $notify = \WP_CLI\Utils\make_progress_bar( 'Generating users', $count );
 
                for ( $i = $total; $i < $limit; $i++ ) {
                        $login = sprintf( 'user_%d_%d', $blog_id, $i );
index 278cf4c..8b8c463 100644 (file)
@@ -407,3 +407,10 @@ function mustache_render( $template_name, $data ) {
        return $m->render( $template, $data );
 }
 
+function make_progress_bar( $message, $count ) {
+       if ( \cli\Shell::isPiped() )
+               return new \WP_CLI\NoOp;
+
+       return new \cli\progress\Bar( $message, $count );
+}
+