OSDN Git Service

A helper method to prompt the user for some detail
authorDaniel Bachhuber <d@danielbachhuber.com>
Mon, 19 Aug 2013 22:33:44 +0000 (15:33 -0700)
committerDaniel Bachhuber <d@danielbachhuber.com>
Mon, 19 Aug 2013 22:33:44 +0000 (15:33 -0700)
php/class-wp-cli.php

index da3a32b..6d907f3 100644 (file)
@@ -165,6 +165,25 @@ class WP_CLI {
        }
 
        /**
+        * Prompt a user for some input
+        */
+       static function prompt( $question, $required = false ) {
+
+               do {
+
+                       self::out( $question . ': ' );
+
+                       $response = trim( fgets( STDIN ) );
+                       if ( $required && $response )
+                               $required = false;
+
+               } while( $required );
+
+               return $response;
+       }
+
+
+       /**
         * Read a value, from various formats
         *
         * @param mixed $value