Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* fix Bug #11068: No way to read plain "-" option [cardoe]

git-svn-id: http://svn.php.net/repository/pear/packages/Console_Getopt/trunk@237494 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 5a2a0fcae27b1f82b58f80b4418361f5646afc4d 1 parent c904610
authored June 12, 2007
4  Console/Getopt.php
@@ -127,6 +127,10 @@ function doGetopt($version, $args, $short_options, $long_options = null)
127 127
                 $error = Console_Getopt::_parseLongOption(substr($arg, 2), $long_options, $opts, $args);
128 128
                 if (PEAR::isError($error))
129 129
                     return $error;
  130
+            } elseif ($arg == '-') {
  131
+                // - is stdin
  132
+                $non_opts = array_merge($non_opts, array_slice($args, $i));
  133
+                break;
130 134
             } else {
131 135
                 $error = Console_Getopt::_parseShortOption(substr($arg, 1), $short_options, $opts, $args);
132 136
                 if (PEAR::isError($error))
44  Console/tests/bug11068.phpt
... ...
@@ -0,0 +1,44 @@
  1
+--TEST--
  2
+Console_Getopt [bug 11068]
  3
+--SKIPIF--
  4
+--FILE--
  5
+<?php
  6
+$_SERVER['argv'] =
  7
+$argv = array('hi', '-fjjohnston@mail.com', '--to', 'hi', '-');
  8
+require_once 'Console/Getopt.php';
  9
+$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'f:t:',
  10
+array('from=','to=','mailpack=','direction=','verbose','debug'));
  11
+if(PEAR::isError($ret))
  12
+{
  13
+	echo $ret->getMessage()."\n";
  14
+	echo 'FATAL';
  15
+	exit;
  16
+}
  17
+
  18
+print_r($ret);
  19
+?>
  20
+--EXPECT--
  21
+Array
  22
+(
  23
+    [0] => Array
  24
+        (
  25
+            [0] => Array
  26
+                (
  27
+                    [0] => f
  28
+                    [1] => jjohnston@mail.com
  29
+                )
  30
+
  31
+            [1] => Array
  32
+                (
  33
+                    [0] => --to
  34
+                    [1] => hi
  35
+                )
  36
+
  37
+        )
  38
+
  39
+    [1] => Array
  40
+        (
  41
+            [0] => -
  42
+        )
  43
+
  44
+)
23  package.xml
@@ -27,9 +27,9 @@ short and long options.
27 27
   <email>cellog@php.net</email>
28 28
   <active>yes</active>
29 29
  </helper>
30  
- <date>2007-02-17</date>
  30
+ <date>2007-06-12</date>
31 31
  <version>
32  
-  <release>1.2.2</release>
  32
+  <release>1.2.3</release>
33 33
   <api>1.2.1</api>
34 34
  </version>
35 35
  <stability>
@@ -38,8 +38,7 @@ short and long options.
38 38
  </stability>
39 39
  <license uri="http://www.php.net/license">PHP License</license>
40 40
  <notes>
41  
- * fix Bug #4475: An ambiguous error occurred when specifying similar longoption name.
42  
- * fix Bug #10055: Not failing properly on short options missing required values
  41
+ * fix Bug #11068: No way to read plain &quot;-&quot; option [cardoe]
43 42
  </notes>
44 43
  <contents>
45 44
   <dir name="/">
@@ -68,6 +67,22 @@ short and long options.
68 67
  <changelog>
69 68
   <release>
70 69
    <version>
  70
+    <release>1.2.2</release>
  71
+    <api>1.2.1</api>
  72
+   </version>
  73
+   <stability>
  74
+    <release>stable</release>
  75
+    <api>stable</api>
  76
+   </stability>
  77
+   <date>2007-02-17</date>
  78
+   <license uri="http://www.php.net/license">PHP License</license>
  79
+   <notes>
  80
+ * fix Bug #4475: An ambiguous error occurred when specifying similar longoption name.
  81
+ * fix Bug #10055: Not failing properly on short options missing required values
  82
+   </notes>
  83
+  </release>
  84
+  <release>
  85
+   <version>
71 86
     <release>1.2.1</release>
72 87
     <api>1.2.1</api>
73 88
    </version>

0 notes on commit 5a2a0fc

Please sign in to comment.
Something went wrong with that request. Please try again.