support --long-opt=arg
authorMichael Wallner <mike@php.net>
Fri, 6 Mar 2015 10:45:17 +0000 (11:45 +0100)
committerMichael Wallner <mike@php.net>
Fri, 6 Mar 2015 10:45:17 +0000 (11:45 +0100)
bin/pharext
src/pharext/CliArgs.php
tests/src/pharext/CliArgsTest.php

index 641f4f50627e67bb5c63ae6ddc712d610d833bbb..07bdaa54e897ef422c3cefe2a12a344b24ceb743 100755 (executable)
Binary files a/bin/pharext and b/bin/pharext differ
index d753931ee7a5e0f86f7e21cd16dc41860dbc8f16..99992bd321cca327e2b2e6e72300dd97c9b0c941 100644 (file)
@@ -127,6 +127,13 @@ class CliArgs implements \ArrayAccess
                                        return "-$s";
                                }, str_split(substr($o, 1))));
                                $o = $argv[$i];
+                       } elseif ($o{0} === '-' && strlen($o) > 2 && $o{1} === '-' && 0 < ($eq = strpos($o, "="))) {
+                               $argc++;
+                               array_splice($argv, $i, 1, [
+                                       substr($o, 0, $eq++),
+                                       substr($o, $eq)
+                               ]);
+                               $o = $argv[$i];
                        }
 
                        if (!isset($this->spec[$o])) {
index ff05c8ff8cc6c05e408e1ed70418ef7e0f3f88ba..4e77b208ab15efbc52aae17130f9e887ee6a6d05 100644 (file)
@@ -112,6 +112,14 @@ class CliArgsTest extends \PHPUnit_Framework_TestCase
                }
                $this->assertTrue(isset($error));
        }
+       
+       public function testLongEquals() {
+               $this->assertNull($this->args->configure);
+               foreach ($this->args->parse(1, ["--configure=--with-lib=/opt/lib"]) as $error) {
+                       throw new \Exception("Unexpected parse error: $error");
+               }
+               $this->assertSame(["--with-lib=/opt/lib"], $this->args->configure);
+       }
 
        public function testValidate() {
                $this->args->compile([